psql.exe - 密码验证在Windows中失败

use*_*100 16 postgresql

我是PostgreSQL中的菜鸟.我在windows7上安装了ver 9.2.在安装过程中它要求输入密码并输入密码.现在,每当我运行d:\ tools\PostgreSQL9.2\bin\psql.exe时,它都会要求输入密码.当我输入密码时,它不接受,并显示"用户密码验证失败"user1".我已经重新安装了两次.我也尝试输入我的系统密码.

我正试图让下面的命令工作

psql.exe -f db/codedb.sql development
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能让这个工作?

Ric*_*ton 25

尝试连接时设置用户名.

psql.exe -U username -d dbname -f somefile.sql
Run Code Online (Sandbox Code Playgroud)

您可能在安装期间设置了默认的"postgres"用户.不确定你是否创造过任何其他人.

要添加其他用户和数据库,只需将postgres连接到postgres数据库并执行以下操作:

CREATE USER myuser WITH ENCRYPTED PASSWORD 'secret';
CREATE DATABASE mydb OWNER myuser;
Run Code Online (Sandbox Code Playgroud)

如果您的机器是安全的,您可能还想设置密码文件


sol*_*anv 10

在pg_hba.conf中更改"trust"而不是"md5"以连接到数据库并更改密码.

    --------------------configuration in pg_hba.conf---------------
    local   all         all                               trust  
    local   all         postgres                          trust          
    host    all         all         ::1/128               trust
Run Code Online (Sandbox Code Playgroud)