使用標(biāo)準(zhǔn)包連接到帶有 go 應(yīng)用程序的 mysql 實(shí)例時(shí)遇到問題。這是我的連接字符串/日志 [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 服務(wù),使用 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 服務(wù) ? 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.有什么我錯(cuò)過或許可的嗎?
1 回答

慕桂英3389331
TA貢獻(xiàn)2036條經(jīng)驗(yàn) 獲得超8個(gè)贊
得到了來自 mav 的 kubernetes-slack 的回復(fù)。我正在訪問mysql-service
一個(gè)錯(cuò)誤的container-port
. 默認(rèn) mysql 端口是3306
. 我以為我正在使用一個(gè)自定義容器來暴露3340
.
- 1 回答
- 0 關(guān)注
- 219 瀏覽
添加回答
舉報(bào)
0/150
提交
取消