Unable to Login as root on phpMyAdmin
1 min read

Unable to Login as root on phpMyAdmin

phpMyAdmin is a popular free and open source administration tool for MySQL and MariaDB. However, it is not unusual to encounter some issues during and after installation. One example would be the inability to log in to the 'root' MySQL user.

phpMyAdmin is a popular free and open source administration tool for MySQL and MariaDB. Many users like myself use it to manage their databases for their web applications. However, it is not unusual to encounter some head scratchers when installing. One example would be the inability to log in to the 'root' MySQL user.

The Error

Often new users to phpMyAdmin encounter an issue where they are unable to log in to their phpMyAdmin instance using their root MySQL user. Often, this comes in the form of a login error message that states:

Access denied for user 'root'@'localhost'

This will occur even if the password used is correct.

What does this error mean?

Simply, this error means that PHPMyAdmin was unable to successfully log in to MySQL using the provided root credentials.

This is due to a change way back in MySQL 5.7 where the root user requires sudo privileges - which PHPMyAdmin does not use.

How to fix this error?

Thus, to fix this error it is best practice to create a new user for phpmyadmin and grant it the necessary privileges. To do so, log in to MySQL and create a user (replace '<your_password>' with a password of your choosing).

CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED BY '<your_password>';

GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;

FLUSH PRIVILEGES;

If during the installation of PHPMyAdmin you chose a different password than the one you elected above creating the new phpmyadmin MySQL user, you may need to edit a config file. Specifically, the one located at /etc/dbconfig-common/phpmyadmin.conf.

Use the following command to edit the file.

sudo nano /etc/dbconfig-common/phpmyadmin.conf

Then, you will need to make changes to this section - replacing '<your_password>' with your phpmyadmin user's password.

# dbc_dbuser: database user
# the name of the user who we will use to connect to the database
dbc_dbuser='phpmyadmin'
# dbc_dbpass: database user password
# the password to use with the above username when connecting
# to a database, if one is required
dbc_dbpass='<your_password>'

After the above changes and additions have taken place you should be able to successfully log in and manage your databases.


Should you have any trouble, send me a message and I'll do my best to help out.

Enjoying these posts? Subscribe for more