Unable to Access CloudSQL MYSQL5.7 From Service Account Using CLI

Viewed 209

I have simple cloudsql instance for MYSQL_5_7 with enable_iam_authentication flag on.

I have added service account or IAM user and want to access the instance using mysql client.

I am using cloudsql auth proxy:

./cloud_sql_proxy -instances=watchful-pier-333707:us-central1:test-002=tcp:3306 --enable_iam_login

Accessing the DB with below command: mysql -u root -p --host 127.0.0.1

Using Built-in user root I am successfully able to access the instance.

When I am trying to access the DB with IAM user/service account using below command, I am getting "Lost connection to MySQL server at 'reading authorization packet', system error: 0".

mysql -u <user_name> -p --host 127.0.0.1 user_name is the one I can see as added user in user's list

Following this documentation - this

Can anyone please help. Thanks in advance!

2 Answers

Automatic IAM AuthN isn't yet available for MySQL. Once it is, we'll update the proxy docs.

The solution with CLI is using below command:

MYSQL_PWD=`gcloud auth print-access-token` mysql --enable-cleartext-plugin --host=127.0.0.1 --user=<user_name>

Make sure you have authorized the service account and gave it token creator role.

Related