用户连接,没有通过JDBC在Postgresql 8.4上设置密码 [英] Connect as user with no password set on Postgresql 8.4 via JDBC
问题描述
我正在尝试通过JDBC驱动程序连接到Ubuntu 10.10中的 PostgreSQL
8.4数据库。我通过 jdbc:postgresql:localhost:5433 / dbname
进行连接,因为PostgreSQL在非默认端口5433上运行,所以我必须指定端口。
I'm trying to connect to a PostgreSQL
8.4 DB in Ubuntu 10.10 via the JDBC drivers. I'm connecting via jdbc:postgresql:localhost:5433/dbname
because PostgreSQL is running on a non-default port 5433 so I have to specify the port.
我已经编辑了我的 postgresql.conf
来设置 listen_addresses =*
。我知道即使它是localhost,它仍然使用TCP / IP通过JDBC连接。
I've already edited my postgresql.conf
to set listen_addresses = "*"
. I understand that even though it's localhost, it's still using TCP/IP to connect via JDBC.
我的问题是我创建了一个没有密码的用户。如果我没有使用 DriverManager.connect(url)
指定密码,则会出现错误,指示我需要指定用于身份验证的密码。我尝试的每个密码,包括空字符串,都无法通过数据库进行身份验证。
My problem is that I created a user without a password. If i do not specify a password with DriverManager.connect(url)
, it errors indicating that I need to specify a password for authentication. Every password I try, including empty string, fails to authenticate with the DB.
我如何连接?
编辑:
如果连接错误的端口,则错误为:PSQLException:连接被拒绝。检查主机名和端口是否正确以及postmaster是否接受TCP / IP连接。当尝试连接正确的端口时,我收到PSQLException:FATAL:用户user的密码验证失败。这可以通过下面接受的答案来解决。
If connecting over wrong port, the error is : PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. When attempting to connect on the correct port, I'm getting PSQLException: FATAL: password authentication failed for user "user". THis is remedied by the accepted answer below.
推荐答案
如果你有 pg_hba.conf
设置为要求 md5
身份验证且用户没有密码,则无法进行身份验证。
If you have pg_hba.conf
set to require md5
authentication and the user has no password, then no authentication can occur.
ALTER USER the_user_name PASSWORD 'give_it_a_password';
或者,使用 ident
或(对于localhost)只有,不安全)信任
在 pg_hba.conf
中对该用户/ db组合进行身份验证,如果你真的没有密码的话。这通常是一个坏主意,只需设置一个密码就好了。
Alternately, use ident
or (for localhost only, unsafe) trust
authentication for that user/db combo in pg_hba.conf
if you really must have no password. This is usually a bad idea, it's much better to just set a password.
演示:
$ psql -q -U postgres postgres
postgres=# CREATE USER nopw;
CREATE ROLE
$ psql -h localhost -U nopw postgres
Password for user nopw: [pressed enter]
psql: fe_sendauth: no password supplied
$ psql -q -U postgres postgres
postgres=# ALTER USER nopw PASSWORD 'test';
postgres=# \q
$ psql -q -h localhost -U nopw postgres
Password for user nopw: [entered 'test' then pressed enter]
postgres=>
这篇关于用户连接,没有通过JDBC在Postgresql 8.4上设置密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!