DBI problem: Can't connect to MySQL server on 'localhost' (10061

T

Ted Byers

I know this arises from time to time, and yes, I have tried everything
mentioned in the MySQL reference manual

I know the server (MySQL 5.1.50) is running. All of the following
work perfectly:

mysql -h localhost --port=33066 -u MyUID -pMyPassword merchants2
mysql -h 127.0.0.1 --port=33066 -u MyUID -pMyPassword merchants2
mysql -h 192.168.2.8 --port=33066 -u MyUID -pMyPassword merchants2

All the above connect and let me run any SQL statement.

But the following scriptlet dies on the last statement with the error:
DBI connect('database=merchants2;host=localhost','rejbyers',...)
failed: Can't connect to MySQL server on 'localhost' (10061)

use strict;
use DBI;
my $db='merchants2';
my $hostname = 'localhost';
my $port = '33066';
my $user = 'MyUID';
my $dbpwd = 'MyPassword';

my $dbh = DBI->connect("DBI:mysql:database=$db;host=$hostname",
$user, $dbpwd, {RaiseError => 1});


The is especially frustrating since precisely the same perl code works
perfectly on all my other machines (that are running the same MySQL
server version and using the same perl - 64 bit Activestate Perl 5.12.

I am at a loss to know why.

Is there a way to have DBI provide more information about WHY it can't
connect?

Thanks

Ted
 
U

Uri Guttman

TB> mysql -h localhost --port=33066 -u MyUID -pMyPassword merchants2
TB> mysql -h 127.0.0.1 --port=33066 -u MyUID -pMyPassword merchants2
TB> mysql -h 192.168.2.8 --port=33066 -u MyUID -pMyPassword merchants2

TB> my $port = '33066';

TB> my $dbh = DBI->connect("DBI:mysql:database=$db;host=$hostname",
TB> $user, $dbpwd, {RaiseError => 1});

i don't see $port in the connect call. dunno if mysql uses that value
for the default port but all your mysql commands set it but not the dbi
connect.

uri
 
H

hymie!

In our last episode, the evil Dr. Lacto had captured our hero,
mysql -h localhost --port=33066 -u MyUID -pMyPassword merchants2
mysql -h 127.0.0.1 --port=33066 -u MyUID -pMyPassword merchants2
mysql -h 192.168.2.8 --port=33066 -u MyUID -pMyPassword merchants2

33066 is not the default mysql port.
my $port = '33066';

my $dbh = DBI->connect("DBI:mysql:database=$db;host=$hostname",
$user, $dbpwd, {RaiseError => 1});

You define $port but never use it.

--hymie! http://lactose.homelinux.net/~hymie (e-mail address removed)
-------------------------------------------------------------------------------
 
T

Ted Byers

I know this arises from time to time, and yes, I have tried everything
mentioned in the MySQL reference manual

I know the server (MySQL 5.1.50) is running.  All of the following
work perfectly:

mysql -h localhost --port=33066 -u MyUID -pMyPassword merchants2
mysql -h 127.0.0.1 --port=33066 -u MyUID -pMyPassword merchants2
mysql -h 192.168.2.8 --port=33066 -u MyUID -pMyPassword merchants2

All the above connect and let me run any SQL statement.

But the following scriptlet dies on the last statement with the error:
DBI connect('database=merchants2;host=localhost','rejbyers',...)
failed: Can't connect to MySQL server on 'localhost' (10061)

use strict;
use DBI;
my $db='merchants2';
my $hostname = 'localhost';
my $port = '33066';
my $user = 'MyUID';
my $dbpwd = 'MyPassword';

my $dbh = DBI->connect("DBI:mysql:database=$db;host=$hostname",
                    $user, $dbpwd, {RaiseError => 1});

The is especially frustrating since precisely the same perl code works
perfectly on all my other machines (that are running the same MySQL
server version and using the same perl - 64 bit Activestate Perl 5.12.

I am at a loss to know why.

Is there a way to have DBI provide more information about WHY it can't
connect?

Thanks

Ted

Thanks Uri and Hymie.

That was it.

Changing :

my $dbh = DBI->connect("DBI:mysql:database=$db;host=$hostname",
$user, $dbpwd, {RaiseError => 1});


To:

my $dbh = DBI->connect("DBI:mysql:database=$db;host=$hostname;port=
$port",
$user, $dbpwd, {RaiseError => 1});

Fixes things.

Thanks for pointing out something I ought to have seen.
 
R

Rainer Weikusat

[...]
Is there a way to have DBI provide more information about WHY it can't
connect?

DBI can be told to generate very detailed debugging output by using
the tracing facilitiy, see TRACING in the corresponding manpage.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top