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

mysql -h -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'@''.

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.

closed as off topic by Zoredache, mdpc, kce, Ward, Khaled Feb 5 '13 at 7:57

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.


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.

  • I did check that; when logging in with the mysql command, the user can indeed use the intended database. – user157518 Feb 4 '13 at 18:30
  • Right; but is it possible you typoed the database name in your DBH connection string? – Jeff Albert Feb 4 '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 4 '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=<DBNAME>;host=<HOSTADDRESS>"; $dbh->connect($dsn, $user, $pass, $options); – Jeff Albert Feb 4 '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 4 '13 at 18:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.