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、初始化数据库;
4、启动postgresql并设置为开机自启动;
|
systemctl restart postgresql systemctl enable postgresql |
5、登进数据库看看状态;(可略)
|
su - postgres psql \du (查看角色) \l (列出所有数据库) \q (退出) |
6、创建角色(postgresql中的用户)和数据库实例;
|
su - postgres createuser dbuser createdb -e -O dbuser dbname |
7、给新用户设定密码
|
su - postgres psql \password dbuser (输入两次密码) vim /var/lib/pgsql/data/pg_hba.conf |
在/var/lib/pgsql/data/pg_hba.conf中,将默认验证方法
|
host all all 127.0.0.1/32 ident |
改为密码验证
|
host all all 127.0.0.1/32 md5 |
8、重启数据库,让新的验证方法生效
|
systemctl restart postgresql |
9、新用户登录数据库;
|
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 (查看当前库中的表) create table test1 (t1 int, t2 varchar(20)); \dp \d test1 (查看表结构) 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 |
|