Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > DBI problem: Can't connect to MySQL server on 'localhost' (10061

Reply
Thread Tools

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

 
 
Ted Byers
Guest
Posts: n/a
 
      08-24-2011
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','rejb yers',...)
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
 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      08-24-2011
>>>>> "TB" == Ted Byers <(E-Mail Removed)> writes:

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

--
Uri Guttman -- uri AT perlhunter DOT com --- http://www.perlhunter.com --
------------ Perl Developer Recruiting and Placement Services -------------
----- Perl Code Review, Architecture, Development, Training, Support -------
 
Reply With Quote
 
 
 
 
hymie!
Guest
Posts: n/a
 
      08-25-2011
In our last episode, the evil Dr. Lacto had captured our hero,
Ted Byers <(E-Mail Removed)>, who said:

>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 http://www.velocityreviews.com/forums/(E-Mail Removed)
-------------------------------------------------------------------------------
 
Reply With Quote
 
Ted Byers
Guest
Posts: n/a
 
      08-25-2011
On Aug 24, 6:06*pm, Ted Byers <(E-Mail Removed)> wrote:
> 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','rejb yers',...)
> 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;po rt=
$port",
$user, $dbpwd, {RaiseError => 1});

Fixes things.

Thanks for pointing out something I ought to have seen.
 
Reply With Quote
 
Rainer Weikusat
Guest
Posts: n/a
 
      08-25-2011
Ted Byers <(E-Mail Removed)> writes:

[...]

> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DBI Mysql storing DBI:binary, trouble with character 26 Jerome Hauss Ruby 0 10-13-2004 03:04 PM
DBI cannot connect to mysql at a specified socket location Zhiqiang Ye Perl Misc 1 08-02-2004 08:07 PM
DBI and DBI::Oracle packages configuration ulloa Perl 1 07-22-2004 05:52 PM
dbi:mysql mysql has gone away Paul Vudmaska Ruby 0 04-21-2004 06:19 PM
Seen this message? Can't connect to local MySQL server through socket '/tmp/mysql.sock' Allen Marshall Perl Misc 1 01-24-2004 10:55 PM



Advertisments