Today I just had to work on a Linux box (CentOS 5) for which I didn’t knew the root password for MySQL so I had to reset it. If you ever face the same problem, here’s how to do it :
- Stop the MySQL daemon : service mysqld stop
- Start MySQL in safe mode with the –skip-grant-tables and -u root options in background : mysqld_safe –skip-grant-tables -u root &
- Start the command line client as root : mysql -u root
- Issue the MySQL command to reset the root password : UPDATE mysql.user SET Password=PASSWORD(‘newpwd’) WHERE User=’root’;
- Issue the flush privileges command : FLUSH PRIVILEGES;
- Quit the command line tool : quit
- Stop the MySQL process : kill `cat /var/run/mysqld/mysqld.pid`
- Restart the MySQL daemon : service mysqld start
- Log in as root to make sure the new password is active : mysql -u root -p
Here’s a screenshot so you can see how it actually goes :








Top Commentators