1

我可以列出我的 Cloud SQL 实例中的数据库,但我无法连接到它。

gcloud beta sql databases list --instance=dbinstance  
NAME                CHARSET  COLLATION  
information_schema  utf8     utf8_general_ci  
main                utf8     utf8_general_ci  
mysql               utf8     utf8_general_ci  
performance_schema  utf8     utf8_general_ci  

它将我的本地机器添加到授权列表中。我可以通过控制台看到这一点。但它无法连接:

gcloud beta sql connect dbinstance --user=root  
Whitelisting your IP for incoming connection for 5 minutes...  
Connecting to database with SQL user [root].  
Enter password:   
ERROR 2003 (HY000): Can't connect to MySQL server on '{db ip}' (110)

它未配置为使用 SSL。

4

1 回答 1

2

一些想法:

A. 用户root可能没有在数据库实例上被授权,期间。

  1. 转到https://console.cloud.google.com/sql/instances/dbinstance/users
  2. 那里列出了用户root吗?
  3. 如果是这样,是否可以从任何 IP 地址获得 root 权限?(用“%”表示)

B. 如果用户root确实从任何主机获得了 'dbinstance' 的授权,那么您的本地网络上可能存在防火墙问题。

  1. 在您的项目中,通过单击控制台站点顶部导航中类似>_的图标打开 Cloud Shell 。这允许您在 GCP 网络内移动,而不是通过本地网络可能设置的任何防火墙。
  2. 在 Cloud Shell 中,键入:gcloud beta sql connect dbinstance --user=root
  3. 它应该询问您的密码。输入它。

如果root的密码不起作用,即使在 Cloud Shell 中,请尝试重置密码(dbinstance 控制台页面上的用户选项卡,root条目旁边的三个点,选择“更改密码”。

如果root 的密码在 Cloud Shell 环境中有效,则您已确定问题出在本地计算机和数据库实例之间。大多数情况下是防火墙问题。

于 2018-02-20T20:53:59.827 回答