天天看点

Centos下使用postgresql数据库

Centos下使用postgresql数据库

    • yum安装postgresql
    • 数据库配置
    • 数据备份
    • 声明

yum安装postgresql

//配置yum的postgresql数据库镜像
#yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y
//安装数据库
#yum install postgresql10-server 
 //初始化数据库
#/usr/pgsql-10/bin/postgresql-10-setup initdb
//启动数据库
#systemctl start postgresql-10.service 
           

数据库配置

//初始化时默认创建postgres新的系统用户
#su - postgres
//启动postgresql数据库的客户端sql交互命令
#psql 
//修改数据库用户postgres的密码为postgres
#ALTER USER postgres WITH PASSWORD 'postgres'; 
//退出psql交互
#\q 
//退出用户
#exit 
//	以下修改为配置远程访问
#find / -name postgresql.conf 
#vim /var/lib/pgsql/10/data/postgresql.conf 
	listen_addressses="*"
	port = 5432 
           

数据备份

//数据库导出
pg_dump -h 127.0.0.1 databasetest -U postgres -p 5432  -f databasetest.sql
//导入
psql -h 0.0.0.0  -d databasetest -U postgres -p 5432 -f databasetest.sql
//导入可能失败,表格已存在,建议先删除再导入。
           

声明

以上内容均来源于实用中的网络和官方查找,若有批漏或侵权请告知。

这世上,没有谁活得比谁容易,只是有人在呼天抢地,有人在默默努力。