Reputation: 4840
I'd like to use the Cloud Shell to run database migrations on my 2nd gen Cloud Sql instance.
I found an example in the docs for how to connect using gcloud
. But when I run the command Im getting an error:
$ gcloud beta sql connect my-instance --user=root
ERROR: (gcloud.beta.sql.connect) Invalid instance property.
But, even if this does work Im not sure how to connect from my python script that performs my migrations. What connection string would I use? Would I need to manually whitelist the Cloud Shell IP for access?
Upvotes: 7
Views: 20687
Reputation: 1265
You should set your project first with : gcloud config set project projectname
After that you can do again : gcloud sql instances describe my_instance_name
Upvotes: -1
Reputation: 761
Edit
The instructions above did not work, it was showing another message.
The first time you'll need to run the command below:
gcloud beta sql connect <instance id> --project <project id>:us-central1 --user root
Also, I switch to my project in the console:
gcloud config set project <project id>
However, I am now getting another error:
ERROR: (gcloud.beta.sql.connect) The client is not authorized to make this request.
I guess I'll need to allow the clients...
Another Edit re Allowing Clients
To finally connect to the DB I had install Google SQL Proxy.
I set it up with FUSE (I use a Mac). After opening a connection following the instructions in the Google Docs. I was able to connect via the mysql command line.
$ mysql -u root -p -S <localtion of cloud sql proxy folder>/<project id>:us-central1:<db instance id>
Original
Just figured this one out. Here's how to do it:
Click on the instance you want to connect
In the Overview
section, scroll down to Properties
.
In Properties
you will see Instance connection name
. It will look something like <your project>:us-central1:<instance name>
Use that in the command:
$ gcloud beta sql connect <your project>:us-central1:<instance name> --user root
Upvotes: 4