phpMyAdmin – Access Denied

Recently, I encountered the error “Access Denied” right after a fresh phpMyAdmin installation on one of my desktop machines running on an older Ubuntu version. Even though I was sure that the password entered was correct, the application was throwing this error. Really annoying, right ?

After some googling and experimenting with the application & database configuration, I found the MySQL Authentication Plugin to be the culprit. I am sharing the details if this would help someone who encounters similar situation.

You may get the following error while trying to connect to mysql database via phpMyAdmin application.

Common Error : Cannot log in to the MySQL server
mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES)

Additional to that, sometimes there would be an additional error which may look like below.

Connection for controluser as defined in your configuration failed.

For fixing the controluser error, check the content of the file /etc/phpmyadmin/config-db.php and confirm that the mysql username & password is saved correctly.

For root user, you may check the login using the command

mysql -u root -p

Enter the root password when prompted.

Sometimes eventhough the password is correct, phpmyadmin wont let you in. Its because of the Authentication Plugin, which happened in my case.

Common Authentication plugins used in MySQL are – caching_sha2_password, mysql_native_password, mysql_clear_password, sha256_password, auth_socket etc

A simple mysql query from SQL prompt would reveal the authentication plugin associated with each user.

mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;

Run the query below to change the authentication plugin used for the user who you are trying to login as.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypassword';
FLUSH PRIVILEGES;

Now you should be able to access your phpMyAdmin interface and play with the databases.

Leave a Reply

Your email address will not be published. Required fields are marked *