PostgreSQL安装和建立用户和建立数据库

1、安装

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

 Centos 6 安装postgresql 10sql

添加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

安装客户端:centos

yum install postgresql10

安装服务端:bash

yum install postgresql10-server

启动数据并初始化:post

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

2、建立用户和数据库

# su - postgres -- 首先切换到postgres

-bash-4.1$ psql  -- 输入psql
psql (10.5)
Type "help" for help.

postgres=# 

 建立用户spa

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

须要注意:postgresql

  1. 要以英文分号结尾code

  2.密码须要引号包裹server

建立数据库

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

将数据库得权限,所有赋给某个用户

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

3、数据库的导入导出

导入整个数据库

psql -U username databasename < /data/dum.sql -- 用户名和数据库名
相关文章
相关标签/搜索