我创建了第二代 MySQL SQL 实例。我在 Compute Cloud 上创建了一个 VM。我按照说明通过以下方式启动了 SQL 代理:
./cloud_sql_proxy -instances=redmine=tcp:3306 -credential_file=/home/sudheer/redmine1.json
2017/12/21 05:43:00 using credential file for authentication; email=redmine1@gavika-test-cloud.iam.gserviceaccount.com
2017/12/21 05:43:00 Listening on 127.0.0.1:3306 for redmine
2017/12/21 05:43:00 Ready for new connections
如您所见,代理已启动并准备好监听连接。从另一个终端,我尝试连接到代理并收到以下消息:
mysql -u root --host=127.0.0.1 -p
Enter password:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
在代理端,我看到这条消息:
2017/12/21 05:43:34 New connection for "redmine"
2017/12/21 05:43:35 couldn't connect to "redmine": ensure that the account has access to "redmine" (and make sure there's no typo in that name). Error during createEphemeral for redmine: googleapi: got HTTP response code 404 with body: Not Found
我不确定缺少什么。我向 IAM 成员提供了项目编辑者和 SQL 客户端角色。
更新:我自己找到了解决方案。INSTANCE_CONNECTION_NAME 不正确。它的格式是:
project_name:region:instance_name
您可以从实例详情页面获取实例连接名称。