May 25, 2017

How to Recover the MySQL root Password

MySQL Logo

Forgot your MySQL root password? No problem, you just need to start MySQL with a flag to tell it to ignore any username and password restrictions which might be in place. Once that is done you can successfully recover the MySQL root password by setting a new password.

Root access is required to edit the following files and to execute commands. Log in as root (su) or simply prepend sudo to all commands that require root privileges.

Stop MySQL

Stop the MySQL server process.

/etc/init.d/mysql stop

Start MySQL without authentication

Start the MySQL server process with the –skip-grant-tables option so that it will not prompt for a password.

mysqld_safe --skip-grant-tables &

Connect to MySQL and setup a new root password

Please replace PASSWORD with the new MySQL root password.

mysql -u root -p
use mysql;
update user set password=PASSWORD("PASSWORD") where user='root';
flush privileges;
quit

Stop MySQL

Stop the MySQL server.

/etc/init.d/mysql stop

Start MySQL and test the root password

Start the MySQL server and test the root password.

/etc/init.d/mysql start
mysql -u root -p

Comments

  1. It’s really a cool and useful piece of info. I’m satisfied that you just shared this helpful information with us. Please keep us up to date like this. Thanks for sharing.

Speak Your Mind