0

I have a remote MySQL server. I can log in from the client machine using:

mysql -h 172.16.0.7 -u mysqlUser -p

and it connects fine.

When I use a simple DBH connection in Perl, with same credentials, the MySql server comes back with Access denied for user 'mysqlUser'@'172.16.0.5'.

That IP has been explicitly granted access in the database.

Both servers are running Centos 6.3. Perl is 5.10.1; MySQL is 14.14.

mgorven
  • 30,615
  • 7
  • 79
  • 122
user157518
  • 11
  • 2

1 Answers1

0

DBH requires that you specify a database name as part of your DSN when connecting, while the CLI client does not; if you attempt to connect to a database on which your user has no permission (or one which does not exist) you'll be rejected with the same 'access denied' message you mention. That's the first thing I'd check.

Jeff Albert
  • 1,987
  • 9
  • 14
  • I did check that; when logging in with the mysql command, the user can indeed use the intended database. – user157518 Feb 04 '13 at 18:30
  • Right; but is it possible you typoed the database name in your DBH connection string? – Jeff Albert Feb 04 '13 at 18:33
  • No, but--lets say the db is called widgets. I have it as "widgets" in the perl script. Should it instead be "dbservername:widgets" or something like that? – user157518 Feb 04 '13 at 18:37
  • Annoyingly, there's no standard for this from one DBD to another, so it's not especially well documented, but the MySQL DSN format is: $dsn = "DBI:mysql:database=;host="; $dbh->connect($dsn, $user, $pass, $options); – Jeff Albert Feb 04 '13 at 18:41
  • Based on output from DBI->trace(5), I see now that it was parsing a susbtring of the password was a variable. I switched to single quotes on the password instead, and now it's passing the password properly, and I'm able to authenticate. Thanks very much for your input! – user157518 Feb 04 '13 at 18:55
  • Glad it worked out for you. – Jeff Albert Feb 04 '13 at 18:58