OSETC TECH

How To Reset Forgotten MySQL Root Password

In this post you’ll see how to reset MySQL Root Password when you Forgot it on linux operating system. typically, if you want to change the password of mysql root user, it just login it with root user password and then update user table, so it can change it easily.but when you lost your root password of mysql, how to login the mysql if you don’t know the current password? or how to reset the MySQL Root Password:

Reset Forgotten MySQL Root Password

Firstly ,you need to stop the current MySQL service, issue the following command:

$sudo /etc/init.d/mysql stop

or

$sudo /etc/init.d/mysqld stop

Then , start MySQL service in safe mode using “mysqld_safe” command, it will skip the grant tables which store the passwords. issue the following command:

$sudo mysqld_safe --skip-grant-tables

You’ll find that mysqld has been startup up, now you can connect to mysql service without password.

Next, login the mysql with root user, enter:

$sudo mysql -u root

Last, try to reset MySQL root user password, issue the following command:

use mysql;

update user set password=PASSWORD("<new password>") where User='root';

flush privileges;

quit;

So far, MySQL root user password has been resetted, try to verify it by connecting with new password.

Restart the MySQL service again so that quit the safe mode to enter into normal mode, issue the below command:

$sudo /etc/init.d/mysql restart

or

$sudo /etc/init.d/mysqld restart

Login the MySQL with new password:

$sudo mysql -u -p

System will show up password prompt, the issue the password for authentication.

done….