Specifying the DB to connect with gcloud sql

后端 未结 2 1980
小蘑菇
小蘑菇 2021-02-01 15:37

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:



        
相关标签:
2条回答
  • 2021-02-01 16:14

    In the meanwhile the beta version of the gcloud sql connect command has added support for a --database=<dbname> flag

    Entire command:
    gcloud beta sql connect INSTANCE [--database=DATABASE, -d DATABASE] [--user=USER, -u USER] [GCLOUD_WIDE_FLAG …]

    https://cloud.google.com/sdk/gcloud/reference/beta/sql/connect

    0 讨论(0)
  • 2021-02-01 16:20

    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.

    0 讨论(0)
提交回复
热议问题