Shell连接PostgreSQL

# /bin/bash

result=`psql -U hrsdxg -h 172.0.0.1 -d database -p123456 << EOF
SELECT * FROM TABLE
EOF`

# psql -U USERNAME -h HOST -d DATABASE -pPORT

# result用于接受SQL的返回值


# 报错1:
#   psql:command not found
# 解决:
#   在Linux上运行 locate psql | grep /bin 命令, 会打印出psql的路径,如:/home/hyshf/HrsHD-35/hrserver/dbserver/bin/psql
#   将该路径添加到环境变量:
#   export PATH=/home/hyshf/HrsHD-35/hrserver/dbserver/bin:$PATH
#   export PATH=/home/hyshf/HrsHD-35/hrserver/dbserver/bin/psql:$PATH

你可能感兴趣的:(Shell连接PostgreSQL)