• 技术文章 >数据库 >PostgreSQL

    postgresql如何新建数据库

    爱喝马黛茶的安东尼爱喝马黛茶的安东尼2019-12-25 10:46:26原创2655

    一、安装

    可以参考postgresql官网安装教程:https://www.postgresql.org/download/linux/redhat/

    Centos 6 安装postgresql 10

    添加RPM:

    -- centos 6 安装 postgresql 10
    yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-centos10-10-2.noarch.rpm
    -- centos 7 安装 postgresql  10
    yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

    安装客户端:

    yum install postgresql10

    安装服务端:

    yum install postgresql10-server

    启动数据并初始化:

    service postgresql-10 initdb
    chkconfig postgresql-10 on
    service postgresql-10 start

    二、创建用户和数据库

    # su - postgres -- 首先切换到postgres
    -bash-4.1$ psql  -- 输入psql
    psql (10.5)
    Type "help" for help.
    postgres=#

    创建用户

    postgres=# create user username with password '****';
    CREATE ROLE
    postgres=#

    需要注意:

    (1)要以英文分号结尾

    (2)密码需要引号包裹

    创建数据库

    postgres=# create database dbtest owner username; -- 创建数据库指定所属者
    CREATE DATABASE
    postgres=#

    将数据库得权限,全部赋给某个用户

    postgres=# grant all on database dbtest to username; -- 将dbtest所有权限赋值给username
    GRANT
    postgres=#

    三、数据库的导入导出

    导入整个数据库

    psql -U username databasename < /data/dum.sql -- 用户名和数据库名

    Python学习网,大量的免费PostgreSQL入门教程,欢迎在线学习!

    专题推荐:postgresql 新建 数据库
    品易云
    上一篇:mysql和postgresql的区别有哪些 下一篇:如何退出postgresql

    相关文章推荐

    • postgresql怎么备份数据库• postgresql如何创建数据库• postgresql如何删除数据库• postgresql怎么还原数据库

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网