指定要与gcloud sql连接的数据库 [英] Specifying the DB to connect with gcloud sql

查看:148
本文介绍了指定要与gcloud sql连接的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

连接到Google Cloud SQL实例时,是否可以指定我要连接的数据库?

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

似乎尝试连接到与用户名相同的数据库,但是如果不是这种情况怎么办? (我不想创建一个名为MY_USER的虚拟数据库,只是为了能够跳转到我想要的数据库).

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).

以下是命令gcloud beta sql的文档,但我在此看不到任何有用的信息:

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

推荐答案

gcloud sql connect当前不允许您指定数据库名称.有一个公开的问题要添加: https://issuetracker.google.com/issues/69314375

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

同时,您可以通过使用PGDATABASE环境变量来解决此问题:

In the meantime, you can work around this by utilizing the PGDATABASE environment variable:

例如

PGDATABASE=mydb gcloud sql connect myinstance

您可以创建一个shell别名来为您执行此操作.

You could create a shell alias to do this for you.

这篇关于指定要与gcloud sql连接的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆