2014 年 8 月 27 日
1、安裝epel;
|
rpm -ivh http://mirrors.hustunique.com/epel/beta/7/x86_64/epel-release-7-0.2.noarch.rpm |
或者
2、安裝postgresql;
3、初始化數(shù)據(jù)庫;
4、啟動postgresql并設(shè)置為開機(jī)自啟動;
|
systemctl restart postgresql systemctl enable postgresql |
5、登進(jìn)數(shù)據(jù)庫看看狀態(tài);(可略)
|
su - postgres psql \du (查看角色) \l (列出所有數(shù)據(jù)庫) \q (退出) |
6、創(chuàng)建角色(postgresql中的用戶)和數(shù)據(jù)庫實例;
|
su - postgres createuser dbuser createdb -e -O dbuser dbname |
7、給新用戶設(shè)定密碼
|
su - postgres psql \password dbuser (輸入兩次密碼) vim /var/lib/pgsql/data/pg_hba.conf |
在/var/lib/pgsql/data/pg_hba.conf中,將默認(rèn)驗證方法
|
host all all 127.0.0.1/32 ident |
改為密碼驗證
|
host all all 127.0.0.1/32 md5 |
8、重啟數(shù)據(jù)庫,讓新的驗證方法生效
|
systemctl restart postgresql |
9、新用戶登錄數(shù)據(jù)庫;
|
psql -U dbuser -d dbname -h 127.0.0.1 (輸入之前的密碼) |
10、玩耍;(以下操作皆在postgresql終端中)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
\dp (查看當(dāng)前庫中的表) create table test1 (t1 int, t2 varchar(20)); \dp \d test1 (查看表結(jié)構(gòu)) select * from test1 limit 10; insert into test1 (t1,t2) values (11, 'ccccc'), (22, 'aaaa'); select * from test1 limit 10; truncate table test1; select * from test1 limit 10; drop table test1; select * from test1 limit 10; \dp |
|