0

我已经在我的机器上安装了 Postgres,我正在尝试使用Perl.

$database = "heatmap";
$user = "postgres";
$password = "<password>";

#connect to Postgres database
my $db = DBI->connect(
        "DBI:Pg:database=$db;",
        $user,
        $password
) or die "Can't Connect to database: $DBI::errstr\n";

但是,我收到以下错误:

DBI connect('database=;','postgres',...) failed: FATAL:  password authentication failed for user "souzamor" at C:/Users/souzamor/workspace/Parser/Parser.pl line 13.
Can't Connect to database: FATAL:  password authentication failed for user "souzamor"

souzamor是我的 Windows 用户名。但是,我正在尝试以postgres. 我继续创建了一个名为souzamorPostgres 的用户,但我得到了:

DBI connect('database=;','souzamor',...) failed: FATAL:  database "user='souzamor'" does not exist at C:/Users/souzamor/workspace/Parser/Parser.pl line 13.
Can't Connect to database: FATAL:  database "user='souzamor'" does not exist

我对 Postgres 完全陌生。有任何想法吗?谢谢

4

2 回答 2

6

我想你的意思是

my $db = DBI->connect(
        "DBI:Pg:database=$database",

代替

my $db = DBI->connect(
        "DBI:Pg:database=$db;",

编辑

据此应该是:

my $dbh = DBI->connect("dbi:Pg:dbname=$database", $user, $password);
于 2012-06-27T12:45:29.947 回答
0

你想连接到你在评论中说的mysql

#connect to MySQL database
my $db = DBI->connect(
        "DBI:Pg:database=$db;",
        $user,
        $password

但不知何故为什么你使用 DBI::Pg << 而不是使用模块 DBI::mysql ?

*PG - PostgreSQL

如果我的答案错误,请纠正我

于 2013-11-13T15:31:39.653 回答