dougou6213 2016-11-13 06:01
浏览 340
已采纳

连接到kubernetes mysql服务时,go-mysql连接被拒绝

I have a problem when connecting to a mysql instance with a go app using standard package. This is my connection string/log

    [13 Nov 16 13:53 +0000] [INFO] connecting to MySQL.. root:awsomepass@tcp(a-mysql-0:3340)/db?charset=utf8&parseTime=True&loc=Local
    2016/11/13 13:53:25 dial tcp 10.108.1.35:3340: getsockopt: connection refused

I tried

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

here is how I make connection, just basic, with string concatenation only

db, err := sql.Open("mysql", "root:awsomepass@tcp(a-mysql-0:3340)/db?charset=utf8&parseTime=True&loc=Local")
if err != nil {
    log.Fatal(err)
}

I can ping the service, connect to it with mysql-client from a different pod.

    # can connect without port for service
    / # mysql -u root -h a-mysql-0 -p
    Enter password:
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MySQL connection id is 11
    Server version: 5.7.16 MySQL Community Server (GPL)

    Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    MySQL [(none)]> Ctrl-C -- exit!
    Aborted

    # can't' connect with port for service
    / # mysql -u root -h a-mysql-0:3340 -p
    Enter password:
    ERROR 2005 (HY000): Unknown MySQL server host 'a-mysql-0:3340' (-3)

and the mysql-service

    ➜  stg git:(develop) ✗ kubectl describe svc a-mysql-0
    Name:            a-mysql-0
    Namespace:        default
    Labels:            name=a-mysql-0
                tier=database
                type=mysql
    Selector:        name=a-mysql-0,tier=database
    Type:            ClusterIP
    IP:            None
    Port:            a-mysql-0    3340/TCP
    Endpoints:        10.108.1.35:3340
    Session Affinity:    None
    No events.

Is there anything I have missed or permission?

展开全部

  • 写回答

1条回答 默认 最新

  • doulong6761 2016-11-13 22:36
    关注

    got a response from kubernetes-slack, from mav. I am accessing the mysql-service to a wrong container-port. default mysql port was 3306. I thought I was using a custom container that exposes 3340.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 传人记程序做的plc 485从机程序该如何写
  • ¥15 已知手指抓握过程中掌指关节、手指各关节和指尖每一帧的坐标,用贝塞尔曲线可以拟合手指抓握的运动轨迹吗?
  • ¥50 libwebsockets 如何添加其他socket事件回调
  • ¥50 实现画布拖拽算子排布,通过flink实现算子编排计算,请提供思路
  • ¥15 esium自定义材质拉伸问题
  • ¥15 cmake+mingw使用<mysqlx/xdevapi.h>报错
  • ¥15 eNSP中防火墙的使用
  • ¥15 不能对数据库增删改但是可以查询
  • ¥15 关于#mlnet#的问题:mlnet相关请求(语言-c#)
  • ¥15 lvgl7.11怎么做出文字被选中的效果
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部