Database Postgresql:createdb为没有密码的用户提示密码

Database Postgresql:createdb为没有密码的用户提示密码,database,postgresql,Database,Postgresql,我在pgsql中创建了一个没有密码的新用户。但当我尝试为该用户创建数据库时,它会提示输入密码 >createuser -d -S -R -U postgres test1 Password: >createdb -U test1 db1 Password: 我尝试了超级用户密码,但它给出了错误: createdb: could not connect to database template1: FATAL: password authentication failed for

我在pgsql中创建了一个没有密码的新用户。但当我尝试为该用户创建数据库时,它会提示输入密码

>createuser -d -S -R -U postgres test1
Password:
>createdb -U test1 db1
Password:
我尝试了超级用户密码,但它给出了错误:

createdb: could not connect to database template1: FATAL:  password authentication failed for user "test1"
请帮忙,
谢谢

有一种通过提示密码创建用户的替代方法。 您可以在创建用户时提供-P选项。 比如:

createuser-d-S-R-U postgres测试1

这可能对你有用

psql -c "CREATE DATABASE mydb" "user=postgres dbname=postgres password=something_secret"
您需要在命令提示符下运行此命令。转到PostgreSQL文件夹,在那里可以找到程序
psql
,然后尝试此命令
mydb
将是数据库名称

参考:


感谢:和

您能编辑您的答案吗?您的示例未显示实际的
-P
选项。。。