在PostgreSQL中,可以使用CREATE DATABASE
命令創建資料庫。
語法:
CREATE DATABASE database_name;
這裏,database_name
是指定要創建的資料庫的名稱。
PostgreSQL使用UI創建資料庫
在您的系統中安裝PostgreSQL後,打開開始菜單,然後單擊pgAdmin。會得到一個這樣的頁面:
打開pgAdmin,第一次打開可能需要你輸入密碼,結果如下 -
右鍵單擊PostgreSQL 9.6
並將PostgreSQL連接到本地主機伺服器。
右鍵單擊資料庫(Databases),轉到新資料庫,將出現一個彈出框,如下圖所示 -
然後鍵入您要的資料庫名稱,這裏創建的資料庫名稱是:zaixian_db,如下圖所示 -
點擊保存(Save)就可以了。
創建新的資料庫(zaixian_db)如下圖所示 -
PostgreSQL使用查詢工具創建資料庫
打開SQL Shell(psql),執行以下創建語句 -
create database testdb;
執行結果如下 -
查看資料庫 -
postgres=# \l
資料庫列表
名稱 | 擁有者 | 字元編碼 | 校對規則 | Ctype | 存取許可權
-----------+----------+----------+--------------------------------+--------------------------------+-----------------------
postgres | 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
testdb | postgres | UTF8 | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 |
zaixian_db | postgres | UTF8 | Chinese (Simplified)_China.936 | Chinese (Simplified)_China.936 |
(5 行記錄)
postgres=#
或者在 pgAdmin 的左側中查看,結果如下 -
上一篇:
PostgreSQL安裝(Windows)
下一篇:
PostgreSQL刪除資料庫