When connecting to a Google Cloud SQL instance, is there a way to specify the database I want to connect to?
This is the command I execute and the error I get:
$ gcloud beta sql connect MY_INSTANCE --user=MY_USER Whitelisting your IP for incoming connection for 5 minutes...done. Connecting to database with SQL user [MY_USER].Password for user MY_USER: psql: FATAL: database "MY_USER" does not exist
It seems to try to connect to a database that has the same name than the user, but what when that's not the case? (I don't want to create a dummy DB called MY_USER just to be able to jump to the DB I want).
Here are the docs for the command gcloud beta sql
, but I don't see anything useful for this there: https://cloud.google.com/sdk/gcloud/reference/beta/sql/connect
In the Google Cloud console, go to the Cloud SQL Instances page. To open the Overview page of an instance, click the instance name. Select Connections from the SQL navigation menu. In the Authorized networks section, click Add network and enter the IP address of the machine where the client is installed.
Cloud SQL is a fully-managed database service that helps you set up, maintain, manage, and administer your relational databases on Google Cloud Platform. You can use Cloud SQL with MySQL, PostgreSQL, or SQL Server.
Cloud SQL automatically ensures your databases are reliable, secure, and scalable so that your business continues to run without disruption. Cloud SQL automates all your backups, replication, encryption patches, and capacity increases—while ensuring greater than 99.95% availability, anywhere in the world.
gcloud sql connect
does not currently allow you to specify the database name. There is a open issue to add it: https://issuetracker.google.com/issues/69314375
In the meantime, you can work around this by utilizing the PGDATABASE
environment variable:
e.g.
PGDATABASE=mydb gcloud sql connect myinstance
You could create a shell alias to do this for you.
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