postgres创建用户,表

使用createuser来创建用户

 

[plain]  view plain copy print ?
 
  1. [postgres@web1 ~]$ /data/pgsql/bin/createuser --help  
  2. createuser creates a new PostgreSQL role.  
  3.   
  4. Usage:  
  5.   createuser [OPTION]... [ROLENAME]  
  6.   
  7. Options:  
  8.   -c, --connection-limit=N  connection limit for role (default: no limit)  
  9.   -d, --createdb            role can create new databases  
  10.   -D, --no-createdb         role cannot create databases (default)  
  11.   -e, --echo                show the commands being sent to the server  
  12.   -E, --encrypted           encrypt stored password  
  13.   -i, --inherit             role inherits privileges of roles it is a  
  14.                             member of (default)  
  15.   -I, --no-inherit          role does not inherit privileges  
  16.   -l, --login               role can login (default)  
  17.   -L, --no-login            role cannot login  
  18.   -N, --unencrypted         do not encrypt stored password  
  19.   -P, --pwprompt            assign a password to new role  
  20.   -r, --createrole          role can create new roles  
  21.   -R, --no-createrole       role cannot create roles (default)  
  22.   -s, --superuser           role will be superuser  
  23.   -S, --no-superuser        role will not be superuser (default)  
  24.   -V, --version             output version information, then exit  
  25.   --interactive             prompt for missing role name and attributes rather  
  26.                             than using defaults  
  27.   --replication             role can initiate replication  
  28.   --no-replication          role cannot initiate replication  
  29.   -?, --help                show this help, then exit  
  30.   
  31. Connection options:  
  32.   -h, --host=HOSTNAME       database server host or socket directory  
  33.   -p, --port=PORT           database server port  
  34.   -U, --username=USERNAME   user name to connect as (not the one to create)  
  35.   -w, --no-password         never prompt for password  
  36.   -W, --password            force password prompt  
  37.   
  38. Report bugs to <pgsql-bugs@postgresql.org>.  
  39. [postgres@web1 ~]$   
  40. [postgres@web1 ~]$   
  41. [postgres@web1 ~]$ /data/pgsql/bin/createuser zhongwc -P  
  42. Enter password for new role:   
  43. Enter it again:   
  44. [postgres@web1 ~]$   

 

 

使用createdb创建数据库

 

[plain]  view plain copy print ?
 
  1. [postgres@web1 ~]$ /data/pgsql/bin/createdb --help  
  2. createdb creates a PostgreSQL database.  
  3.   
  4. Usage:  
  5.   createdb [OPTION]... [DBNAME] [DESCRIPTION]  
  6.   
  7. Options:  
  8.   -D, --tablespace=TABLESPACE  default tablespace for the database  
  9.   -e, --echo                   show the commands being sent to the server  
  10.   -E, --encoding=ENCODING      encoding for the database  
  11.   -l, --locale=LOCALE          locale settings for the database  
  12.       --lc-collate=LOCALE      LC_COLLATE setting for the database  
  13.       --lc-ctype=LOCALE        LC_CTYPE setting for the database  
  14.   -O, --owner=OWNER            database user to own the new database  
  15.   -T, --template=TEMPLATE      template database to copy  
  16.   -V, --version                output version information, then exit  
  17.   -?, --help                   show this help, then exit  
  18.   
  19. Connection options:  
  20.   -h, --host=HOSTNAME          database server host or socket directory  
  21.   -p, --port=PORT              database server port  
  22.   -U, --username=USERNAME      user name to connect as  
  23.   -w, --no-password            never prompt for password  
  24.   -W, --password               force password prompt  
  25.   --maintenance-db=DBNAME      alternate maintenance database  
  26.   
  27. By default, a database with the same name as the current user is created.  
  28.   
  29. Report bugs to <pgsql-bugs@postgresql.org>.  
  30. [postgres@web1 ~]$   
  31. [postgres@web1 ~]$   
  32. [postgres@web1 ~]$ /data/pgsql/bin/createdb zwcdb  
[plain]  view plain copy print ?
 
  1. [postgres@web1 ~]$ psql -U zhongwc -d zwcdb  
  2. psql (9.2.2)  
  3. Type "help" for help.  
  4.   
  5. zwcdb=> help  
  6. You are using psql, the command-line interface to PostgreSQL.  
  7. Type:  \copyright for distribution terms  
  8.        \h for help with SQL commands  
  9.        \? for help with psql commands  
  10.        \g or terminate with semicolon to execute query  
  11.        \q to quit  
  12. zwcdb=>   



创建表

 

 

[plain]  view plain copy print ?
 
  1. [postgres@web1 data]$ psql -U zhongwc -d zwcdb -h 192.168.1.203 -p 1521  
  2. Password for user zhongwc:   
  3. psql (9.2.2)  
  4. Type "help" for help.  
  5.   
  6. zwcdb=> create table t_zhongwc(pid integer,pname varchar(32),constraint zhongwc_pid_pk primary key(pid));  
  7. NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "zhongwc_pid_pk" for table "t_zhongwc"  
  8. CREATE TABLE  
  9. zwcdb=>   
  10. zwcdb=> select * from t_zhongwc;  
  11.  pid | pname   
  12. -----+-------  
  13. (0 rows)  


删除表

 

 

[plain]  view plain copy print ?
 
    1. zwcdb=> drop table t_zhongwc;  
    2. DROP TABLE  
    3. zwcdb=> drop table t_zhongwc;  
    4. ERROR:  table "t_zhongwc" does not exist  

转载于:https://www.cnblogs.com/liqing1009/p/5035260.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值