程序员 mysql Android HTML5 java php shell 开源 wordpress 微软 centos linux命令 Windows Ubuntu Firefox google Python nginx linux apache

postgresql 创建 用户,数据库,表

一,创建用户

[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

延伸阅读

评论