sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm安装
sudo yum install -y postgresql14-server可选初始化数据库并启用自动启动:
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb sudo systemctl enable postgresql-14 sudo systemctl start postgresql-14登录postgresql
su - postgres psql退出postgresql
q exit根用户postgres设置登录密码
ALTER USER postgres WITH PASSWORD 'postgres';远程访问配置
postgresql 默认是不支持远程访问,需要修改2个配置文件
进入文件地址vim /var/lib/pgsql/14/data/postgresql.conf
修改如此
LISTEN_ADDRESSES = '*' # WHAT IP ADDRESS(ES) TO LISTEN ON; #COMMA-SEPARATED LIST OF ADDRESSES; #DEFAULTS TO 'LOCALHOST'; USE '*' FOR ALL #(CHANGE REQUIRES RESTART) PORT = 5432 # (CHANGE REQUIRES RESTART) max_connections = 100 # (change requires restart)进入文件地址
vim /var/lib/pgsql/14/data/pg_hba.conf
全部修改为trust不用再认证输入密码
# "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust # Allow replication connections from localhost, by a user with the # replication privilege. local replication all trust host replication all 127.0.0.1/32 trust host replication all ::1/128 trust host all all 0.0.0.0/0 trust查看数据库列表
l创建用户
create USER xxx WITH PASSWORD '123456';创建数据库
create DATAbase xxx;数据库归属关系
GRANT ALL PRIVILEGES ON DATAbase xxx TO xxxx;切换数据库
#先退出 q #再登录数据库,下边为大写U psql -d xxx -U xxx;



