在MySQL中,我使用use database_name;
psql的等价是什么?
在MySQL中,我使用use database_name;
psql的等价是什么?
当前回答
使用下面的语句切换到内部的不同数据库 您的postgreSQL RDMS
\c databaseName
其他回答
连接psql时可以选择数据库。当从脚本中使用它时,这很方便:
sudo -u postgres psql -c "CREATE SCHEMA test AUTHORIZATION test;" test
您只需输入use [dbName]即可在数据库之间进行切换,而无需重新输入密码。
使用\c数据库名或\connect数据库名
(正在使用psql 13.3)
虽然问题中没有明确说明,但目的是连接到特定的模式/数据库。
另一种选择是直接连接到模式。例子:
Sudo -u postgres PSQL -d my_database_name
来源:man psql:
-d dbname
--dbname=dbname
Specifies the name of the database to connect to. This is equivalent to specifying dbname as the first non-option argument on the command line.
If this parameter contains an = sign or starts with a valid URI prefix (postgresql:// or postgres://), it is treated as a conninfo string. See Section 31.1.1, “Connection Strings”, in the
documentation for more information.
在PSQL提示符下,你可以这样做:
\connect (or \c) dbname