[Fixed]: Access denied for user ‘root’@’localhost’

If you have just installed phpmyadmin and unable to login with root user. Then you’re at right place so let’s start now.

The main issue behind it because of MySql 5.7 by default allow to connect with socket.

Access denied for user 'root'@'localhost'

Follow the below steps to fix this issue.

Step 1: Run the mySQL with root access in linux/ubuntu terminal.

sudo mysql

Step 2: Get all the available users:

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

Output:

Step 3: Update the values in the table with command :

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Current-Root-Password';
FLUSH PRIVILEGES;

Step 4: Run the select command again and you’ll see it has changed:

And that’s it. You can run this process after running and completing the sudo mysql_secure_installation command.