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

I'm deplying a server and can't connect to MySql with Perl. I receive the error "Access denied for user 'root'@'localhost' (using password: YES)"

On my users table i have root with all privileges at localhost and also at '%'(any host). I can access the database under 'root' user from the linux shell but with Perl script it does not work.

$dbh = DBI->connect ("DBI:mysql:host=localhost;database=mydb", "root", "mypass", {PrintError => 0, RaiseError => 1});

Replies are listed 'Best First'.
Re: MySql Access Denied
by McA (Priest) on Apr 09, 2014 at 13:05 UTC

    Hi,

    please show us the 'mysql'-commmand you can connect with on the command line.

    McA

Re: MySql Access Denied
by locked_user sundialsvc4 (Abbot) on Apr 09, 2014 at 17:36 UTC

    Also, do not allow your application to connect to the database as a rootly user, lest you run afoul of The Bobby Tables problem.

    (Yes, you would be astounded at just how many web-apps are out there, available to the general public, which do have the authority to issue a DROP TABLE command!   Or, heh heh, GRANT ALL PRIVILEGES TO ...)

    Your application should connect with one or more application-specific IDs which practice the “principle of least privilege.”   The MySQL system should be configured to consider, not only the user-name but also the IP-address that is making the connection.   Each and every user-id should allow only the least amount of access required to do the job at hand, and, where possible, more than one such id should be used as appropriate.

    You may as well start dealing with these issues now.