How to solve MySQL error: Access denied for user ‘root’@’localhost’

In order to fix the error “access denied for user root@localhost’” after MySQL installation, follow the steps below.

First, you would have to type in the command below in your terminal.

sudo su

You will be prompted for the password. Go ahead and enter your super user password.

Next run the command below :

update mysql.user set plugin = ‘mysql_native_password’ where User=’root’

Once this is done, you would need to flush the privileges using the commands below :


Read: How to install MySQL on Ubuntu 18.04

Finally type in the command below to exit :


Now, Simply invoke the command below in your terminal.

mysql -u root -p

You will be asked for the password. Once done, you will login successfully into the console.

If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.


amin nahdy

Amin Nahdy, an aspiring software engineer and a computer geek by nature as well as an avid Ubuntu and open source user. He is interested in information technology especially Linux based ecosystem as well as Windows and MacOS. He loves to share and disseminate knowledge to others in a transparent and responsible way.

Leave a Reply