PostgreSQL 選擇數(shù)據(jù)庫(kù)

2020-04-22 17:46 更新

上一章節(jié)我們講了如何創(chuàng)建數(shù)據(jù)庫(kù),接下來(lái)我們來(lái)討論如何去選擇我們創(chuàng)建的數(shù)據(jù)庫(kù)。

數(shù)據(jù)庫(kù)的命令窗口

PostgreSQL 命令窗口中,我們可以命令提示符后面輸入 SQL 語(yǔ)句:

postgres=#

使用 \l 用于查看已經(jīng)存在的數(shù)據(jù)庫(kù):

postgres=# \l
                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges   
-----------+----------+----------+---------+-------+-----------------------
 postgres  | postgres | UTF8     | C       | C     | 
w3cschooldb  | 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)

接下來(lái)我們可以使用 \c + 數(shù)據(jù)庫(kù)名 來(lái)進(jìn)入數(shù)據(jù)庫(kù):

postgres=# \c w3cschooldb
You are now connected to database "w3cschooldb" as user "postgres".
w3cschooldb=# 

系統(tǒng)命令行窗口

在系統(tǒng)的命令行查看,我么可以在連接數(shù)據(jù)庫(kù)后面添加數(shù)據(jù)庫(kù)名來(lái)選擇數(shù)據(jù)庫(kù):

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

pgAdmin 工具

pgAdmin 工具更簡(jiǎn)單了,直接點(diǎn)擊數(shù)據(jù)庫(kù)選擇就好了,還可以查看一些數(shù)據(jù)庫(kù)額外的信息:


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)