Google Cloud SQL proxy couldn't find default credentials
Solution 1
Two problems may be generating your problem.
To find what is login, using:
gcloud auth login
1. You haven't application default credentials
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
2. You haven't defined your project
After login, you should see:
Your current project is [project-id].
Once again two solutions:
a. Associate a project
If you are not seeing this, do (ref):
gcloud config set project PROJECT_ID
b. Use global --project
flag in the call
In your command associate a project:
.\cloud_sql_proxy -instances=project-id:region-name:instance-id=tcp:3306 --project=project-id
Solution 2
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.
Related videos on Youtube
starleaf1
A programmer and aspiring software developer who specialize in web, especially HTML5, JavaScript, and PHP. Also quite fluent with MySQL, for obvious reasons.
Updated on October 05, 2020Comments
-
starleaf1 over 3 years
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?
-
Tiago Medici over 3 yearsgot an example 4 u youtube.com/watch?v=BBxNHjpys7A&t=33s
-
-
starleaf1 over 7 yearsThe thing still returns the same error. I tried both
gcloud auth application-default login
and using external service account json key. -
cherba over 7 yearsBy any chance you have
GOOGLE_APPLICATION_CREDENTIALS
environment variable set? Also have your tried to use-credential_file
parameter? -
starleaf1 over 7 yearsIt looks like I must set the default project in gcloud to the one which my instance is in. Otherwise, it would just return the error.