一,创建用户
[root @rudder ~]# su postgres //切换用户
bash-3.2$ createuser -P -D -R -e testuser //创建一个用户,-P要设置密码,-R,不参创建其他用户,-D不能创建数据库
Could not change directory to "/root" //报出一个错误
Enter password for new role:
bash-3.2$ cd /home/ //切换到home目录下
bash-3.2$ createuser -P -D -R -e testuser
Enter password for new role:
Enter it again:
CREATE ROLE testuser PASSWORD 'play-_-boy' NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;
CREATE ROLE
[root @rudder ~]# su postgres //切换用户
bash-3.2$ createuser -P -D -R -e testuser //创建一个用户,-P要设置密码,-R,不参创建其他用户,-D不能创建数据库
Could not change directory to "/root" //报出一个错误
Enter password for new role:
bash-3.2$ cd /home/ //切换到home目录下
bash-3.2$ createuser -P -D -R -e testuser
Enter password for new role:
Enter it again:
CREATE ROLE testuser PASSWORD 'play-_-boy' NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;
CREATE ROLE
二,创建数据库,并且登录
bash-3.2$ createdb testuser //创建数据库
CREATE DATABASE
bash-3.2$ psql -U testuser -d testuser //登录数据库
Welcome to psql 8.1.23,the Postgresql interactive terminal.
Type: \copyright for distribution terms
\h for help with sql commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
testuser=>
bash-3.2$ createdb testuser //创建数据库
CREATE DATABASE
bash-3.2$ psql -U testuser -d testuser //登录数据库
Welcome to psql 8.1.23,the Postgresql interactive terminal.
Type: \copyright for distribution terms
\h for help with sql commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
testuser=>
三,创建表,并指定索引 testuser=> create table test(id integer,name varchar(32),constraint testuser_id_pk primary key(id)); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "testuser_id_pk" for table "test" CREATE TABLE