Mysql Root Forgotten Password Recovery
First things first. Log in as root and stop the mysql daemon. Now lets start up the mysql daemon and skip the grant tables which store the passwords.
mysqld_safe --skip-grant-tables
You should see mysqld start up successfully. If not, well you have bigger issues. Now you should be able to connect to mysql without a password.
mysql --user=root mysql
update user set Password=PASSWORD('new-password') where user='root';
flush privileges;
exit;
Now kill your running mysqld, then restart it normally. You should be good to go. Try not to forget your password again.
Other Methods
mysqladmin command to change root password
If you have never set a root password for MySQL, the server does not require a password at all for connecting as root. To setup root password for first time, use mysqladmin command at shell prompt as follows:
$ mysqladmin -u root password NEWPASSWORD |
However, if you want to change (or update) a root password, then you need to use following command
$ mysqladmin -u root -p'oldpassword' password newpass |