我在我的机器上安装了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
身份进行连接。我继续在Postgres中创建了一个名为souzamor
的用户,但我得到了:
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全新。有任何想法吗? 感谢
答案 0 :(得分:6)
我认为你的意思是
my $db = DBI->connect(
"DBI:Pg:database=$database",
而不是
my $db = DBI->connect(
"DBI:Pg:database=$db;",
修改的
根据this,它应该是:
my $dbh = DBI->connect("dbi:Pg:dbname=$database", $user, $password);
答案 1 :(得分:0)
你想连接到你在评论中说的mysql
#connect to MySQL database
my $db = DBI->connect(
"DBI:Pg:database=$db;",
$user,
$password
但不知何故你使用DBI :: Pg&lt;&lt;而是使用模块DBI :: mysql?
* Pg - PostgreSQL
如果答案错误,纠正我