Postgresql:can';无法连接新创建的用户
以下是错误:Postgresql:can';无法连接新创建的用户,postgresql,ubuntu-16.10,Postgresql,Ubuntu 16.10,以下是错误: $ psql -h localhost -U kMbjQ6pR9G -d fzvqFILx0d Password for user kMbjQ6pR9G: psql: FATAL: password authentication failed for user "kMbjQ6pR9G" FATAL: password authentication failed for user "kMbjQ6pR9G" 我可能错过了使用新PostgreSQL的配置步骤 以下是我尝试使用
$ psql -h localhost -U kMbjQ6pR9G -d fzvqFILx0d
Password for user kMbjQ6pR9G:
psql: FATAL: password authentication failed for user "kMbjQ6pR9G"
FATAL: password authentication failed for user "kMbjQ6pR9G"
我可能错过了使用新PostgreSQL的配置步骤
以下是我尝试使用自己的数据库创建新用户的命令行:
sudo -u postgres bash -c "psql -c \"CREATE USER $USER WITH PASSWORD '$PASSWORD';\"" &&
sudo -u postgres bash -c "psql -c \"CREATE DATABASE $DB;\"" &&
sudo -u postgres bash -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE $DB to $USER;\"" &&
#!/bin/bash
if [ -n "$1" ]; then
DB="$1"
else
DB=$(php -r "echo substr(str_shuffle(str_repeat('abcdefghijklmnopqrstuvwxyz', ceil(10/63) )),1,10);")
fi
USER=$(php -r "echo substr(str_shuffle(str_repeat('abcdefghijklmnopqrstuvwxyz', ceil(10/63) )),1,10);")
PASSWORD=$(php -r "echo substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil(20/63) )),1,20);")
sudo -u postgres psql -c "CREATE USER $USER WITH PASSWORD '$PASSWORD';"
sudo -u postgres psql -c "CREATE DATABASE $DB;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $DB to $USER;"
cat << EndOfMessage
POSTGRESQL_ADDON_DB="$DB"
POSTGRESQL_ADDON_HOST="localhost"
POSTGRESQL_ADDON_PASSWORD="$PASSWORD"
POSTGRESQL_ADDON_PORT="5432"
POSTGRESQL_ADDON_USER="$USER"
EndOfMessage
以下是PostgreSQL配置:
$ sudo grep -v ^# /etc/postgresql/9.5/main/pg_hba.conf |grep -v ^$
local all postgres md5
local all all md5
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
以下是我为测试而创建的所有accound:
$ sudo -u postgres bash -c 'psql -c "select * from pg_shadow;"'
Password:
usename | usesysid | usecreatedb | usesuper | userepl | usebypassrls | passwd | valuntil | useconfig
------------+----------+-------------+----------+---------+--------------+-------------------------------------+----------+-----------
av6izmbp9l | 16384 | f | f | f | f | md5a49721ef3f5428e269badc03931baf48 | |
rqmejchq7n | 16386 | f | f | f | f | md54edf3a05ca96a435f94152b75495e9dc | |
yyfiknesu8 | 16388 | f | f | f | f | md5b3d4a03913569abbf318bdc490d0f821 | |
qgv2ryqvdw | 16390 | f | f | f | f | md5d0959b4b5e1ed2982e19e4d0af574b11 | |
postgres | 10 | t | t | t | t | md5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | |
pf09joszuj | 16392 | f | f | f | f | md5a920dc31666459e5f0a96e9430d07f02 | |
我认为这很简单,但我忽略了这一点
谢谢你的支持,
David。尝试连接时是否明确指定了数据库
psql -h localhost -U myuser -d mydb
这是我通常设置用户完全拥有给定数据库的方式:
create role myuser with createdb login encrypted password 'mypassword';
create database mydb with owner 'myuser' encoding 'utf8';
pg_hba.conf:
local myuser mydb md5
...
问题很明显:用户名和数据库名都是小写的 下面是我用来创建用户和他自己的数据库的脚本:
sudo -u postgres bash -c "psql -c \"CREATE USER $USER WITH PASSWORD '$PASSWORD';\"" &&
sudo -u postgres bash -c "psql -c \"CREATE DATABASE $DB;\"" &&
sudo -u postgres bash -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE $DB to $USER;\"" &&
#!/bin/bash
if [ -n "$1" ]; then
DB="$1"
else
DB=$(php -r "echo substr(str_shuffle(str_repeat('abcdefghijklmnopqrstuvwxyz', ceil(10/63) )),1,10);")
fi
USER=$(php -r "echo substr(str_shuffle(str_repeat('abcdefghijklmnopqrstuvwxyz', ceil(10/63) )),1,10);")
PASSWORD=$(php -r "echo substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil(20/63) )),1,20);")
sudo -u postgres psql -c "CREATE USER $USER WITH PASSWORD '$PASSWORD';"
sudo -u postgres psql -c "CREATE DATABASE $DB;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $DB to $USER;"
cat << EndOfMessage
POSTGRESQL_ADDON_DB="$DB"
POSTGRESQL_ADDON_HOST="localhost"
POSTGRESQL_ADDON_PASSWORD="$PASSWORD"
POSTGRESQL_ADDON_PORT="5432"
POSTGRESQL_ADDON_USER="$USER"
EndOfMessage
#/bin/bash
如果[-n“$1”];然后
DB=“$1”
其他的
DB=$(php-r“echo substr(str_shuffle(str_repeat('abcdefghijklmnopqrstuvxyz',ceil(10/63))),1,10);)
fi
USER=$(php-r“echo substr(str_shuffle(str_repeat('abcdefghijklmnopqrstuvwxyz',ceil(10/63))),1,10);)
密码=$(php-r“echo substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvxyzabefghijklmnopqrstuvxyz',ceil(20/63))),1,20;)
sudo-u postgres psql-c“使用密码'$PASSWORD'创建用户$USER;”
sudo-u postgres psql-c“创建数据库$DB
sudo-u postgres psql-c“将数据库$DB上的所有特权授予$USER
猫:我似乎无法理解错误消息。输出在我看来是正常的。只要没有错误消息,就意味着连接成功。您是如何尝试连接的?您会遇到什么样的错误?您已经向我们展示了有关如何创建用户的详细信息,但我们需要了解您所做的哪些操作存在问题,以便提供帮助。您遇到了什么错误?添加了错误消息。