0

I have installed Postgres in my machine, and I'm trying to connect to it using 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";

However, I'm getting the following error:

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 is my Windows username. However, I'm trying to connect as postgres. I went ahead and created an user called souzamor in Postgres, but I got:

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

I'm totally new with Postgres. Any ideas? Thanks

2 Answers 2

6

I think you mean

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

instead of

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

Edit

According to this, it should be:

my $dbh = DBI->connect("dbi:Pg:dbname=$database", $user, $password);
Sign up to request clarification or add additional context in comments.

Comments

0

you want to connect to mysql you said in comment

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

but somehow why you use DBI::Pg << instead using module DBI::mysql ?

*Pg - PostgreSQL

correct me if my answer is wrong

1 Comment

Corrected! Plx check it again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.