加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql 创建 用户,数据库,表

发布时间:2020-12-13 17:09:28 所属栏目:百科 来源:网络整理
导读:一,创建用户 [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


一,创建用户
[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=>

三,创建表,并指定索引 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读