一,创建用户
[root@rudder ~]# su postgres //切换用户 bash-3.2$ createuser -P -D -R -e playboy //创建一个用户,-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 playboy Enter password for new role: Enter it again: CREATE ROLE playboy PASSWORD 'play-_-boy' NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN; CREATE ROLE
二,创建数据库,并且登录
bash-3.2$ createdb playboy //创建数据库 CREATE DATABASE bash-3.2$ psql -U playboy -d playboy //登录数据库 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 playboy=>
三,创建表,并指定索引
playboy=> create table test(id integer,name varchar(32),constraint playboy_id_pk primary key(id)); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "playboy_id_pk" for table "test" CREATE TABLE
转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/pgsql/1524.html