Recover mysql root password

– Stop mysql
# /etc/init.d/mysql stop

– Lauch mysql with –skip-grant-tables (WARNING: your mysql server will launch without any password authentication, so please protect it first with a firewall or something if it’s world accessible)
# mysqld_safe --skip-grant-tables

– Login as root without a password
$ mysql -u root

– Change the password
mysql> use mysql;
mysql> update user set password=PASSWORD("your_new_root_password") where User='root';
mysql> flush privileges;
mysql> quit

– Stop mysql
# /etc/init.d/mysql stop

– Start mysql again to re-enable authentication
# /etc/init.d/mysql start

Leave a Reply