PostgreSQL数据库:掌握两种登录方法

发表时间: 2024-03-27 16:49

方法1:

psql postgresql://postgres:pg123@172.17.0.3:5434/postgres

postgresql协议名称

postgresql 用户名

pg123 密码

172.17.0.3 ip

5434 port

postgres 需要访问的数据库名称

方法2:

psql -U postgres -h172.17.0.3 -p5434 -dpostgres

-U 用户名

-h 数据库IP

-p 数据库端口

-d 需要访问的数据库名称

如果想用psql直接连接数据库,需要通过设置postgres用户的环境变量来实现:

export PGHOME=/usr/pgsql-13

export PGUSER=postgres

export PGPORT=5434

export PGHOST=localhost

export PATH=$PGHOME/bin:$PATH:$HOME/bin