Every now and then even the best of us will forget an important password - like our mysql server root password. Or perhaps we inherit a running mysql system with no documentation from a previous administrator. Either way, there comes a time when we simply have to reset the root password. With mysql, as long as you have root access to the OS, it is not a difficult task.
First, login and stop the mysql process. How you do this will vary from linux to linux, but will either be:
/etc/init.d/mysql stop or
service mysql stop
Next thing we need to do is to restart the mysql process, telling it to skip using the password table:
Finally connect with the client:
mysql -u root
And then change the password for root:
update user set Password=PASSWORD('new-password-here') where user='root';
Then exit the client, stop the running mysqld process and restart as normal.