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

Discussion in 'Perl Misc' started by Ted Byers, Aug 24, 2011.

  1. Ted Byers

    Ted Byers Guest

    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
    Ted Byers, Aug 24, 2011
    #1
    1. Advertising

  2. Ted Byers

    Uri Guttman Guest

    >>>>> "TB" == Ted Byers <> 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 -------
    Uri Guttman, Aug 24, 2011
    #2
    1. Advertising

  3. Ted Byers

    hymie! Guest

    In our last episode, the evil Dr. Lacto had captured our hero,
    Ted Byers <>, 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
    -------------------------------------------------------------------------------
    hymie!, Aug 25, 2011
    #3
  4. Ted Byers

    Ted Byers Guest

    On Aug 24, 6:06 pm, Ted Byers <> 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','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.
    Ted Byers, Aug 25, 2011
    #4
  5. Ted Byers <> 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.
    Rainer Weikusat, Aug 25, 2011
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Boldra
    Replies:
    0
    Views:
    1,283
    Boldra
    Dec 3, 2003
  2. Bill Loren

    socket error 10061

    Bill Loren, Sep 11, 2003, in forum: Python
    Replies:
    0
    Views:
    403
    Bill Loren
    Sep 11, 2003
  3. Jerome Hauss
    Replies:
    0
    Views:
    167
    Jerome Hauss
    Oct 13, 2004
  4. Francis Hwang
    Replies:
    5
    Views:
    258
    Jesper Rønn-Jensen
    Aug 6, 2005
  5. Allen Marshall
    Replies:
    1
    Views:
    192
    Gunnar Hjalmarsson
    Jan 24, 2004
Loading...

Share This Page