FireBird34 has asked for the wisdom of the Perl Monks concerning the following question:

New to DBI, MySQL, etc, so bear with me on this one. Going through the given examples with DBI, or anyother one I use for that matter, I keep getting this one single error:
DBI connect('database=test;host=xxx.xxx.x.x','username',...) failed: T +imeout of authentication at C:/Perl/site/lib/DBD/mysqlPP.pm line 109 +at database.pl line 7 Can't call method "prepare" on an undefined value at database.pl line +11.
The example code I'm using is:
#!perl use DBI; $dsn = "dbi:mysqlPP:database=test;host=xxx.xxx.x.x"; $dbh = DBI->connect($dsn, "my_username", "my_password"); $drh = DBI->install_driver("mysqlPP"); $sth = $dbh->prepare("SELECT * FROM foo WHERE bla"); $sth->execute; $numRows = $sth->rows; $numFields = $sth->{'NUM_OF_FIELDS'}; $sth->finish;
Any suggestions?

Replies are listed 'Best First'.
Re: Timeout problems (DBI)
by graff (Chancellor) on Sep 14, 2004 at 05:29 UTC
    I'm assuming that you really know of a specific mysql server that's running somewhere, and are really using the appropriate host, user and password parameters to connect to that. (It is of course totally appropriate and correct that you do not include that specific information in any post at PerlMonks.)

    In my own access function for connecting to a mysql server, my dsn string goes like this:

    $dsn = "DBI:mysql:database=test;host=host.name.dom"
    I don't know if that'll make the difference in your case, but it works for me, and it's something that differs between my working code and your non-working code.

    Apart from that, have you determined that you are able to connect to the database by other (non-perl) means -- e.g. can you run a mysql client from the command line and connect to that database using the given user/password/host/dbname values?

    I also tend to set RaiseError to true, so if the connect fails, the script dies right away with an error message. You should at least check for success from the DBI "connect" call, if you're not going to set the RaiseError parameter.

      Well, I've got the problem figured out now... It's not a Perl problem, but a MySQL problem. It's an Access Denied error. No idea why, but I'm still looking around. I can log into 'mysql' via command prompt, however doing the trouble shooting, I can't change my password in it =P I'll still keep messing with it. Since it's not a Perl issue, not worth keeping this going, however I'll still take any input. Thanks for the help =)

      EDIT: I've fixed this somewhat; the program just hangs now, doing nothing... it hangs at the connect command. Can't figure it out...
        I bet it turned out to be a problem in the priveledge table. You probably set your username up to accept connections from localhost and any host but not for the specific IP address that you were calling in your "database=test, host=x.x.x.x" statement. Oh, and dbi:mysqlPP is valid if you have DBI::mysqlPP installed, and dbi:mysql is valid if you have DBI::Mysql installed.