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.
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;
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_dbpass: database user password
# the password to use with the above username when connecting
# to a database, if one is required
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.