本文共 1045 字,大约阅读时间需要 3 分钟。
下面由Linux教程栏目给大家介绍linux 安装postgresql的方法,希望对需要的朋友有所帮助!
通过yum 安装postgresql 相关的包sudo yum install -y postgresql postgresql-server postgresql96-devel postgresql-contrib postgresql-docs
初始化数据库sudo service postgresql initdb
// 根据安装的版本确定postgresql 的版本
eg: sudo service postgresql96 initdb
启动数据库sudo service postgresql start
创建用户和数据// 首先登陆postgres 用户
sudo su postpres psql
// 输入上条命令之后 进入psql ,就可以输入sql 语句
create user testuser with password 'testpwd';
// 创建数据库
create database testdb owner testuser;
// 授予用户操作数据库的权限
grant all privileges on database testdb to testuser;
\q 退出
// 修改配置文件,设置数据可以远程访问
sudo cd /var/lib/pgsql/data
// 编辑文件
sudo vim postgresql.conf
修改文件listen_addresses = 'localhost' 改为 listen_addresses = '*'
修改文件pg_hba.conf
在文件底部添加一行host all all 0.0.0.0/0 md5
// 重启服务
注意: 查看一下data文件的权限是否是 700 ,如果不是修改为700 sudo chmod 700 /var/bin/data/sudo service restart postgresql
测试连接psql -h *.*.*.* -d testdb -U testuser
可能遇到的错误Peer authentication failed for user "postgres"
解决方法sudo vim /var/lib/pgsql/data/pg_hba.conf
host all all peer 改为
host all all trust
转载地址:https://blog.csdn.net/weixin_33073525/article/details/113026079 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!