Forum Moderators: coopster & phranque

Message Too Old, No Replies

DBI MySQL connect error

Can't connect to MySQL

         

slaydude

8:19 pm on Jun 4, 2006 (gmt 0)

10+ Year Member



I'm trying to use the Perl DBI module, but it won't connect to my MySQL server even though all of the credentials are (to the best of my knowledge) correct.

The code I'm using is:

use DBI();
my $dbh = DBI->connect('DBI:mysql:database', 'username', 'password');

where database is the database name, etc. This generates the error:

DBI connect('database','username',...) failed: Access denied for user: 'username@localhost' (Using password: YES)

I can connect to the database successfully using the same credentials from PHP, from the command line, and from Perl via a pipe. System details are as follows:

Linux 2.4.31-ow1
MySQL server 4.0.25
PERL 5.8.0
DBI 1.48
DBD::mysql 2.9008

FYI the script is not a CGI, but one I would like to run from the command line to automate some database maintenance tasks.

Many thanks in advance for any help.

slaydude

slaydude

8:30 pm on Jun 4, 2006 (gmt 0)

10+ Year Member



Answered my own question: I was reading the password in from a file, but forgetting to chomp it, so the password being sent to MySQL ended with a newline. Duh.

coopster

3:07 pm on Jun 5, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, slaydude. Glad you got it sorted. I notice you are on 4.0 yet, if you end up on 4.1 at some point and get similar login issues be advised that there were some authentication issues (message number 9):
[webmasterworld.com...]