无法使用云 SQL 代理从 Google 计算引擎连接到 Google 云 SQL

Can't connect to Google Cloud SQL from Google Compute Engine with Cloud SQL Proxy

我正在尝试使用云 SQL 代理将 GCE 实例连接到云 SQL 实例(第二代)。当我 ssh 到 GCE 实例并且

sudo ./cloud_sql_proxy -dir=/cloudsql

我明白了

2016/07/13 18:59:28 Using gcloud's active project: xxxx-0000
2016/07/13 18:59:29 Error listing instances in xxxx-0000:
    googleapi: Error 403: Access Not Configured.
    Cloud SQL Administration API has not been used in project 000000000000
    before or it is disabled. Enable it by visiting
    https://console.developers.google.com/apis/api/sqladmin/overview?project=000000000000
    then retry.
    If you enabled this API recently, wait a few minutes for the action to
    propagate to our systems and retry., accessNotConfigured
2016/07/13 18:59:29 no Cloud SQL Instances found in these projects: [xxxx-0000]

我已经按照
上的文档进行操作 https://cloud.google.com/sql/docs/compute-engine-access#gce-connect-proxy
https://cloud.google.com/sql/docs/sql-proxy

两个实例都在同一个项目中,并且在 GCE 实例(加上默认实例)上启用了 Cloud SQL API。据我了解,默认 GCE 服务帐户应该能够验证代理。

cloud_sql_proxy-instances 一起使用似乎可行,但在尝试连接时 accessNotConfigured 也会出错。

根据错误消息,您需要通过访问提供的 link.

确保 "Cloud SQL Admin" API 已启用

如果您使用的是第二代 GCloud SQL 实例,还有一种 GUI 方式可以连接您的 Compute Engine 实例。您首先获取计算引擎的外部 IP,并将其包含在 GCloud SQL 仪表板的授权选项卡中。这是一个快速 video

启用 Cloud SQL Admin API 将解决您的问题: