- 工信部备案号 滇ICP备05000110号-1
- 滇公安备案 滇53010302000111
- 增值电信业务经营许可证 B1.B2-20181647、滇B1.B2-20190004
- 云南互联网协会理事单位
- 安全联盟认证网站身份V标记
- 域名注册服务机构许可:滇D3-20230001
- 代理域名注册服务机构:新网数码
CentOS7 yum安装PostgreSQL
一、PostgresSQL的安装
PostgresSQL官网:https://www.landui.com/
1、安装rpm文件
yum install -y https://www.landui.com/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2、安装客户端
yum install postgresql15
3、安装服务端
yum install -y postgresql15-server
4、初始化
/usr/pgsql-15/bin/postgresql-15-setup initdb
5、设置自动启动并且启动postgresql服务
systemctl enable postgresql-15
systemctl start postgresql-15
二、创建用户和数据库
1、使用postgres用户登录(PostgresSQL安装后会自动创建postgres用户,无密码)
su - postgres
2、登录postgresql数据库
3、创建用户和数据库并授权
create user test_user with password 'abc_123'; // 创建用户
create database test_db owner test_user; // 创建数据库
grant all privileges on database test_db to test_user; // 授权
4、退出psql(输入\\q再按回车键即可)
\\q
三、开启远程访问
1、修改/var/lib/pgsql/15/data/postgresql.conf文件,取消 listen_addresses 的注释,将参数值改为“*”
vi /var/lib/pgsql/15/data/postgresql.conf
2、修改/var/lib/pgsql/15/data/pg_hba.conf文件,增加下图红框部分内容
vi /var/lib/pgsql/15/data/pg_hba.conf
3、切换到root用户,重启postgresql服务
systemctl restart postgresql-15.service
4、使用数据库连接工具测试连接
Linux远程链接命令:
# 格式
psql -h 主机IP -p 端口 -U 用户名 -W -d 数据库
# 示例
psql -h 127.0.0.1 -p 5432 -U test_user -d test_db;
Windows中使用工具连接测试:
售前咨询
售后咨询
备案咨询
二维码
TOP