数据库 PostgreSQL 新建用户无法登入

tailang · March 17, 2013 · Last by tailang replied at March 18, 2013 · 7889 hits

第一次使用,网上也看了一些博文,但还是没有解决。 1.具有管理权限的 postgres 用户可以登入:

$psql -U postgres -h localhost

登入成功 2.创建新用户(在 shell 命令行中创建)

$ sudo -u postgres createuser -P test

然后为新建的用户添加密码有创建数据库权限,不是 superuser 3.\du 查看新用户已经存在 4.在 shell 中登入新用户

$ psql -U test -h localhost

并输入密码 提示错误: psql: FATAL: database "test" does not exist

我按照网上所说将修改/etc/postgresql/9.1/main/pg_hba.conf 文件,将

local all all peer

修改为

local all all md5

但还是失败。

错误信息的意思是数据库 "test" 不存在。

psql 登录时如果不加 -d 指定想使用的数据库,默认会去打开与登录用户名相同的数据库。

所以用 createdb test 或者其它什么方法创建一个 test 数据库,或者每次加 -d <dbname> 就行了

@5long 非常感谢,这个折腾了我好久。第一次接触,感觉和 mysql 差别好大。

You need to Sign in before reply, if you don't have an account, please Sign up first.