Ste*_*bbi 3 java linux postgresql jdbc
我正在尝试PostgreSQL通过JDBC驱动程序连接到Ubuntu 10.10中的8.4 DB.我正在连接,jdbc:postgresql:localhost:5433/dbname因为PostgreSQL在非默认端口5433上运行,所以我必须指定端口.
我已经编辑了我postgresql.conf的设置listen_addresses = "*".我知道即使它是localhost,它仍然使用TCP/IP通过JDBC连接.
我的问题是我创建了一个没有密码的用户.如果我没有指定密码DriverManager.connect(url),则会出现错误,表明我需要指定密码进行身份验证.我尝试的每个密码,包括空字符串,都无法通过DB进行身份验证.
我怎么连接?
编辑:如果连接错误的端口,错误是:PSQLException:连接被拒绝.检查主机名和端口是否正确以及postmaster是否接受TCP/IP连接.当尝试连接正确的端口时,我收到PSQLException:FATAL:用户"user"的密码验证失败.这可以通过下面接受的答案来解决.
Cra*_*ger 12
如果您已pg_hba.conf设置为要求md5身份验证且用户没有密码,则不会进行身份验证.
ALTER USER the_user_name PASSWORD 'give_it_a_password';
Run Code Online (Sandbox Code Playgroud)
或者,如果您确实没有密码,请使用ident或(对于仅限localhost,不安全)的trust用户/ db组合pg_hba.conf验证.这通常是一个坏主意,只需设置密码就好了.
演示:
$ 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=>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9352 次 |
| 最近记录: |