
一、安装
可以参考postgresql官网安装教程:https://www.postgresql.org/download/linux/redhat/
Centos 6 安装postgresql 10
添加RPM:
1 2 3 4 | -- centos 6 安装 postgresql 10
yum install https:
-- centos 7 安装 postgresql 10
yum install https:
|
安装客户端:
安装服务端:
1 | yum install postgresql10-server
|
启动数据并初始化:
1 2 3 | service postgresql-10 initdb
chkconfig postgresql-10 on
service postgresql-10 start
|
二、创建用户和数据库
1 2 3 4 5 | # su - postgres -- 首先切换到postgres
-bash-4.1$ psql -- 输入psql
psql (10.5)
Type "help" for help.
postgres=#
|
创建用户
1 2 3 | postgres=# create user username with password '****' ;
CREATE ROLE
postgres=#
|
需要注意:
(1)要以英文分号结尾
(2)密码需要引号包裹
创建数据库
1 2 3 | postgres=# create database dbtest owner username; -- 创建数据库指定所属者
CREATE DATABASE
postgres=#
|
将数据库得权限,全部赋给某个用户
1 2 3 | postgres=# grant all on database dbtest to username; -- 将dbtest所有权限赋值给username
GRANT
postgres=#
|
三、数据库的导入导出
导入整个数据库
1 | psql -U username databasename < /data/dum.sql -- 用户名和数据库名
|
Python学习网,大量的免费PostgreSQL入门教程,欢迎在线学习!