I'm trying to run Google Cloud SQL proxy locally like this:
$ ./cloud_sql_proxy -instances project-name:region-name:instance-id tcp:3306
But it's returning
google: could not find default credentials. See https://developers.google.com/accounts/docs/application-default-credentials for mor information.
My Google Cloud SDK is already installed and logged in to Google.
How do I fix this?
Start the Cloud SQL Auth proxyReplace INSTANCE_CONNECTION_NAME with the instance connection name you copied in the previous step. At the Enter password: prompt, enter the password of your MySQL root user account. Verify that the MySQL prompt appears. You have connected to your database using the mysql client.
The Cloud SQL Auth proxy requires authenticating as a Cloud SQL IAM identity to authorize your connections to a Cloud SQL instance.
Two problems may be generating your problem.
To find what is login, using:
gcloud auth login
If you have a recent version of gcloud you will get:
WARNING: `gcloud auth login` no longer writes application default credentials.
To make your local application use your credentials you need to do (ref):
gcloud auth application-default login
If you don't see this warning consider updating gcloud, with:
gcloud components update
After login, you should see:
Your current project is [project-id].
Once again two solutions:
If you are not seeing this, do (ref):
gcloud config set project PROJECT_ID
--project
flag in the callIn your command associate a project:
.\cloud_sql_proxy -instances=project-id:region-name:instance-id=tcp:3306 --project=project-id
Google application default credentials are managed separately from gcloud credentials.
Use
gcloud auth application-default login
instead to setup your user credentials as application default. See reference for more info.
Previously gcloud auth login
did this, but with more recent Cloud SDK versions this is no longer the case.
Note that switching gcloud configuration or setting account will not update application default credentials. Only commands in gcloud auth application-default
can be used to manage these.
Also to use service account as application default credential you can use it directly by downloading its json key from developer console.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With