场景
PostGresSQL简介与Windows上的安装教程
上面讲了在Windows上的安装教程,在CentOS上怎样安装。
注:
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。
实现
1、去Postgresql的官网,根据自己对应的版本生成安装脚本
https://www.postgresql.org/download/linux/redhat/
这里使用14版本,Centos,脚本内容如下
来到服务器上某目录下新建脚本文件
编辑脚本文件将上面的内容复制进去
赋予脚本执行权限
然后执行脚本文件
2、安装脚本执行成功之后创建用户和数据库并授权,安装成功之后默认会生成postgres用户以及一个postgres数据库,不带密码,为了方便后续使用新建用户和数据库
切换postgres用户登录(PostgresSQL安装后会自动创建postgres用户,无密码)
登录postgresql数据库
创建用户和数据库授权
退出psql
输入 \q 再按回车键
3、配置允许远程连接
修改/var/lib/pgsql/14/data/postgresql.conf,这里14对应自己的数据库版本,取消 listen_addresses 的注释,将参数值改为“*”
添加本地连接地址修改/var/lib/pgsql/14/data/pg_hba.conf
在IPv4下添加一行
host all all 0.0.0.0/0 trust
保存退出,重启服务
4、服务器上开启默认5432端口并重新加载防火墙
5、查看服务状态
6、使用Navicat远程连接