Access denied for user ‘root’@’localhost’

In 5.6, you have to do it:

 sudo mysql -u root
 use mysql; 
 mysql> update user set plugin='' where User='root';

or

 mysql> update user set password=PASSWORD("SET_YOUR_PASSWORD") where user='root';
 mysql> flush privileges; 

In 5.7, you have to do it:

 sudo mysql -u root 
 use mysql;
 mysql> update user set plugin='mysql_native_password' where User='root';
 mysql> update user set password=PASSWORD("SET_YOUR_PASSWORD") where user='root';
 mysql> flush privileges;

Finally, restart the instance/daemon without the –skip-grant-tables option.

sudo /etc/init.d/mysql restart

You should now be able to connect with your new password.

mysql -u root -p

Enter password: my_password

You May Also Like

About the Author: Jafor Iqbal

Leave a Reply