Recovering mysql root password

If you forget mysql root password, you can recover it such as:

Restart mysqld with

mysqld --skip-grant-tables

Then connect mysql using mysql utility without password:

mysql> update mysql.user set Password=Password('newpassword') where User='root';
mysql> flush privileges;

Then restart mysql normally (without --skip-grant-tables)