今天我们来使用 psql 客户端工具连接 PostgreSQL 服务器的命令执行如下:
1.psql -h hostname -p port -U username -W dbname
其中,hostname 表示服务器主机名,默认为本机;port 表示 PostgreSQL 实例服务端口,默认为 5432;username 表示用户名,默认为当前操作系统用户;-W 提示输入密码,默认行为;dbname 表示要连接的数据库,默认和用户名相同。例如:
1.[tony@sqlhost ~]> psql -h 192.168.56.104 -p 5432 -U tony hrdb
2.Password for user tony:
3.psql (12.4)
4.Type "help" for help.
5.
6.hrdb=>
以上命令使用 tony 用户通过 5432 端口连接到服务器 192.168.56.104 上的 hrdb 数据库。
在 psql 提示符中输入help获取使用帮助。
hrdb=> help
You are using psql, the command-line interface to PostgreSQL.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
使用\?命令可以获取 psql 命令相关的帮助信息:
hrdb=> \?
General
\copyright show PostgreSQL usage and distribution terms
\crosstabview [COLUMNS] execute query and display results in crosstab
\errverbose show most recent error message at maximum verbosity
\g [FILE] or ; execute query (and send results to file or |pipe)
\gdesc describe result of query, without executing it
\gexec execute query, then execute each value in its result
\gset [PREFIX] execute query and store results in psql variables
\gx [FILE] as \g, but forces expanded output mode
\q quit psql
\watch [SEC] execute query every SEC seconds
Help
\? [commands] show help on backslash commands
\? options show help on psql command-line options
\? variables show help on special variables
\h [NAME] help on syntax of SQL commands, * for all commands
使用\h命令可以获取 SQL 命令相关的帮助信息:
hrdb=> \h
Available help:
ABORT CREATE FOREIGN DATA WRAPPER DROP ROUTINE
ALTER AGGREGATE CREATE FOREIGN TABLE DROP RULE
ALTER COLLATION CRE
内容加载中...
内容加载中...
内容加载中...