【发布时间】:2015-04-17 15:22:32
【问题描述】:
我已经创建了一个计算引擎实例并安装了 MySQL 也授权云 sql 实例。需要更改一些防火墙设置以打开端口 3306 使用此命令:
$ gcloud compute firewall-rules create FIREWALL_RULE --allow tcp:3306
但仍然无法连接到数据库。我收到以下错误:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
【问题讨论】:
-
通过发出此命令,您将打开默认网络上的 3306 端口。您的实例是在默认网络上运行还是在其他网络上运行?要检查的另一件事是实例上的 iptables。尝试禁用 iptables 进行测试。在授权网络中,您还需要授权实例的公共 IP 而不是私有 IP。
-
检查 Mysql 是否监听所有地址,而不仅仅是本地。在 /etc/mysql/my.cnf(对于 Debian 操作系统)中检查:bind-address = 0.0.0.0
-
我尝试使用 bind-address = 0.0.0.0 和 bind-address = localhost,但它对我也不起作用,收到此错误 ERROR 2002 (HY000): Can't connect to local MySQL server通过套接字 '/var/run/mysqld/mysqld.sock' (2) 在 ssl 上编写此命令时:mysql --host=localhost --user=
--password
标签: java mysql google-compute-engine google-cloud-sql