DEV Community

Cover image for ACCESS DENIED: Reset MySQL root user password

ACCESS DENIED: Reset MySQL root user password

Erika Wiedemann on November 13, 2018

This post was originally written September 10, 2016 during a stressful time in my life - I couldn't access MySQL root. I'm migrating all my persona...
Collapse
 
msgclub4 profile image
msgclub

After upgrading MySQL from the previous version to 5.7, when I had tried to log in to the database as a non-sudo user it shows the following error. But I was enabled to login into the system as sudo user without any issues.

ERROR 1698 (28000): Access denied for user ‘root’@’localhost’.

You can use the following steps to beat MySQL Error 1698 (28000): Access denied for user ‘root’ @ ‘localhost’

In Ubuntu systems running MySQL 5.7 (and later), the root user is authenticated by the auth_socket plugin by default.

$ sudo mysql #No Username to be the provide

mysql> USE mysql;

mysql> SELECT User, Host, plugin FROM mysql.user;

+——————+———————–+

| User | plugin |

+——————+———————–+

| root | auth_socket |

| mysql.sys | mysql_native_password |

| debian-sys-maint | mysql_native_password |

+——————+———————–+

mysql> UPDATE user SET plugin=’mysql_native_password’ WHERE User=’root’;

mysql> FLUSH PRIVILEGES;

mysql> exit;

$ service mysql restart

Right Answer!!

If you want to login to your MySQL server as root from an external program such as phpMyAdmin you have two options.

The first one is to change the authentication method from auth_socket to mysql_native_password. You can do that by running the following command: ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘very_strong_password’;FLUSH PRIVILEGES;

Conclusion: Now you have learned to install troubleshoot the Access Denied error in MySql 5.7 and also you can check detailed solution from expresstechsoftwares.com/mysql-acc...

Collapse
 
rajeshamara profile image
rajeshamara

Your suggestion worked like a charm. Thanks for the help

Collapse
 
imohgenius profile image
Michael Etokakpan

Wow, this was a lifesaver! Thanks!

Collapse
 
sijan8s3 profile image
Sijan Neupane

Thank you! thank you so much!

Collapse
 
salsabilkz profile image
salsabil.kz

If you just run mysql command under root user you will be granted access without asked for password, because socket authentication enabled for root@localhost.

Short way to solve

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new-password';

Collapse
 
arthurz profile image
Arthur

Then it disallows connecting via GUI tools as the MySQL Workbench with error:

You must reset your password using ALTER USER statement before executing this statement.

To overcome this run

SET PASSWORD = PASSWORD('securepassword');

In the mysql shell.

Collapse
 
dvjones89 profile image
Dave Jones • Edited

Thank you for taking the time to write this, Erika. For me, knowing how to run MySQL in safe mode was the trick, after which it was trivial to reset the password for my root user. Thanks for sharing!

Collapse
 
arthurz profile image
Arthur

One must go into the mysql database before applying commands in Step 3

Collapse
 
gamblingrepairman profile image
gamblingrepairman

I owe you a beer if I ever meet you! I have spent 5+ hours on this issue and your answer was the only one that worked!

Collapse
 
hritik14 profile image
Hritik Vijay

Bless you ! May the rain of good luck keep showering upon you. Phewwwww