Encountering the “Access denied for user ‘root’@’localhost'” error is a common headache, especially right after installing phpMyAdmin on a Linux system. This typically happens because MySQL 5.7 (and later versions) often defaults to using the auth_socket plugin for the root user, which prevents standard password-based logins via tools like phpMyAdmin.
In this guide, we will walk through the steps to switch the authentication method to mysql_native_password so you can log in without issues.
Step 1: Open MySQL Terminal
Since you cannot log in normally, you need to access the MySQL prompt using sudo to bypass the password requirement temporarily.
sudo mysql
Step 2: Identify Current User Configuration
Once inside the MySQL shell, check the current authentication plugins assigned to your users.
SELECT user, authentication_string, plugin, host FROM mysql.user;
In the output, you will likely notice that the root user has auth_socket or unix_socket listed under the plugin column.

Step 3: Change Authentication Method
To allow password-based login, you must alter the user to use the native password plugin. Replace 'your_password' with the actual password you want to set for the root user.
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';
After making this change, reload the grant tables to apply the new settings immediately:
FLUSH PRIVILEGES;
Step 4: Verify the Fix
Run the select command from Step 2 again. You should now see mysql_native_password listed for the root user. Exit the terminal:

exit;
Now, try logging into phpMyAdmin or using mysql -u root -p. The “Access Denied” error should be gone!
Discover more from TCMHACK
Subscribe to get the latest posts sent to your email.
