一乃戈、建立數(shù)據(jù)庫連接
接入PostgreSQL數(shù)據(jù)庫: psql -h IP地址 -p 端口 -U 連接用戶名
之后會(huì)要求輸入數(shù)據(jù)庫密碼
二、訪問數(shù)據(jù)庫
1谎倔、列舉數(shù)據(jù)庫:\l
2、選擇數(shù)據(jù)庫:\c 數(shù)據(jù)庫名
3、查看該某個(gè)庫中的所有表:\dt
4、切換數(shù)據(jù)庫:\c interface
5仔役、查看某個(gè)庫中的某個(gè)表結(jié)構(gòu):\d 表名
6、查看某個(gè)庫中某個(gè)表的記錄:select * from apps limit 1;
7恨胚、顯示字符集:\encoding
8骂因、退出psgl:\q
創(chuàng)建 yy 用戶炎咖, 密碼為 yy , 創(chuàng)建 blogbase數(shù)據(jù)庫赃泡,并對(duì) yy 用戶賦予所有權(quán)限
$ sudo su - postgres
$ psql
postgres=# CREATE USER yy WITH PASSWORD 'yy';
CREATE ROLE
postgres=# CREATE DATABASE blogbase;
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON DATABASE blogbase to yy;
GRANT
修改用戶密碼
alter user 用戶名 with password'新密碼';
ALTER ROLE
psql -U yy -d blogbase -h 127.0.0.1
-U:指定用戶寒波,-d:指定數(shù)據(jù)庫,-h:指定服務(wù)器,如有端口用 -p 指定
執(zhí)行上述命令后升熊,如果出現(xiàn)例如 "Password for user yy: " 這樣的語句讓輸入密碼俄烁,輸入密碼后即登錄成功
重命名數(shù)據(jù)庫
alter database blogbase rename to blogbase1;
服務(wù)
查看狀態(tài)
sudo /etc/init.d/postgresql status
啟動(dòng)
sudo /etc/init.d/postgresql start
停止
sudo /etc/init.d/postgresql stop
重啟
sudo /etc/init.d/postgresql restart