PostgreSQL 选择数据库

上一章节我们讲了如何创建数据库,接下来我们来讨论如何去选择我们创建的数据库。

数据库的命令窗口

PostgreSQL 命令窗口Shell shell(psql) 中,我们可以命令提示符后面输入 SQL 语句:

postgres=#

使用 \l 用于查看已经存在的数据库:

postgres=# \l
                                                        数据库列表
   名称    |  拥有者  | 字元编码 |            校对规则            |             Ctype              |       存取权限
-----------+----------+----------+--------------------------------+--------------------------------+-----------------------
 postgres  | postgres | UTF8     | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 |
 runoopsdb | postgres | UTF8     | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 |
 template0 | postgres | UTF8     | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 | =c/postgres          +
           |          |          |                                |                                | postgres=CTc/postgres
 template1 | postgres | UTF8     | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 | =c/postgres          +
           |          |          |                                |                                | postgres=CTc/postgres
(4 行记录)

接下来我们可以使用 \c + 数据库名 来进入数据库:

postgres=# \c runoopsdb
您现在已经连接到数据库 "runoopsdb",用户 "postgres".
runoopsdb=#

系统命令行窗口

在系统的命令行查看,我么可以在连接数据库后面添加数据库名来选择数据库:

$ psql -h localhost -p 5432 -U postgres runoopsdb
Password for user postgres: ****
psql (13.10)
Type "help" for help.
You are now connected to database "runoopsdb" as user "postgres".
runoopsdb=# 

pgAdmin 工具

pgAdmin 工具更简单了,直接点击数据库选择就好了,还可以查看一些数据库额外的信息:

Captcha Code

0 笔记

分享笔记

Inline Feedbacks
View all notes