为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

Go
明月笑刀无情 2022-04-20 17:49:51
使用标准包连接到带有 go 应用程序的 mysql 实例时遇到问题。这是我的连接字符串/日志    [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我试过GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;这是我建立连接的方式,只是基本的,仅使用字符串连接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)}我可以 ping 服务,使用 mysql-client 从不同的 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)和 mysql 服务    ➜  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.有什么我错过或许可的吗?
查看完整描述

1 回答

?
慕桂英3389331

TA贡献2036条经验 获得超8个赞

得到了来自 mav 的 kubernetes-slack 的回复。我正在访问mysql-service一个错误的container-port. 默认 mysql 端口是3306. 我以为我正在使用一个自定义容器来暴露3340.



查看完整回答
反对 回复 2022-04-20
  • 1 回答
  • 0 关注
  • 191 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号