教程 > postgresql 教程 > 阅读:46

postgresql 选择数据库——迹忆客-ag捕鱼王app官网

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

数据库的命令窗口

postgresql 命令窗口中,我们可以命令提示符后面输入 sql 语句:

postgres=#

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

postgres=# \l
                             list of databases
   name    |  owner   | encoding | collate | ctype |   access privileges   
----------- ---------- ---------- --------- ------- -----------------------
 jiyik_db  | postgres | utf8     | c       | c     | 
 postgres  | postgres | utf8     | c       | c     | 
 template0 | postgres | utf8     | c       | c     | =c/postgres           
           |          |          |         |       | postgres=ctc/postgres
 template1 | postgres | utf8     | c       | c     | =c/postgres           
           |          |          |         |       | postgres=ctc/postgres
(4 rows)

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

postgres=# \c jiyik_db
you are now connected to database "jiyik_db" as user "postgres".
jiyik_db=# 

系统命令行窗口

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

$ psql -h localhost -p 5432 -u postgres jiyik_db
password for user postgres: ****
psql (11.12)
type "help" for help.
you are now connected to database "jiyik_db" as user "postgres".
jiyik_db=# 

查看笔记

扫码一下
查看教程更方便
网站地图