If you lose your MySQL root password, do as follows. First of all, stop MySQL:
# service mysql stop
Wait until MySQL shuts down. Then run:
# mysqld_safe --skip-grant-tables &
After that you will be able to login as root without a password:
#mysql -uroot mysql
In the MySQL command line prompt issue the following command:
UPDATE user SET password=PASSWORD("none") WHERE user="root"; FLUSH PRIVILEGES;
Stop the running MySQL instance:
# kill `ps aux | grep -e "--skip-grant" | grep -v grep | awk '{ print $2 }'`
Restart the MySQL service normally:
# service mysql start
At this time your root password is reset to “none” and MySQL will now know the privileges and you’ll be able to login with your new password:
# mysql -uroot -pnone mysql