Resetting forgotten root password in mysql

I forgot my root password for mysql. This is how to restore it
First, I need to stop the server:
%sudo /etc/init.d/mysql stop

then run the server in safe-mode with –skip-grant-tables to enable login without password
%sudo /usr/bin/mysqld_safe --skip-grant-tables &

Then we can login without the password and access mysql database
%mysql --user=root mysql

In MySQL client, do this:
mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root';
Query OK, 2 rows affected (0.04 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

mysql> exit

after this type “fg” and “ctrl-C” to kill the server in safe mode. Now start the server again.
%sudo /etc/init.d/mysql start

Now you can try logging in with the new password:
%mysql --user=root --pass=new-password-here