Tuesday, June 11, 2013

Reset MySQL root password on CentOS 5.x

I had one of those oh-crap moments and forgot the mysql root password in one of my development/test machines.
This is a reblog of someone else's post in case it ever gets deleted, I must say it saved my bacon (or at the very lease a couple hours of hair pulling and reinstall)

Credit to: http://gettechgo.wordpress.com/2012/05/10/how-to-reset-mysql-root-password-linux-o-s/

0. Login as root/su

1. Stop the MySQL service
 
service mysqld stop
 

2. Start MySQL Safe mode with skip grant tables option 
mysqld_safe --skip-grant-tables &
(press ctrl+z to exit, if required)

3. Start the MySQL service

service mysqld start

4. Log into the MySQL server without any password

 mysql -u root -p mysql
 

5. Reset the password for ‘root’ user
UPDATE user SET password=PASSWORD(‘new-password’) where user=’root’;

6. Flush privileges
 
flush privileges;

7. Restart the MySQL service

service mysqld restart
 

8. Log-in with the new password 
mysql -u root -p
<enter new password when prompted>


Cheers,
Noveck