Recover MySQL root password on Debian

Debian is pretty nice in providing a maintenance user, go to /etc/mysql/debian.cnf and locate the password. Given that, login as debian-sys-maint user.

# mysql -udebian-sys-maint -p

mysql> UPDATE mysql.user SET Password=PASSWORD('yournewpassword') WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> q

For passwordless root login, you might put the updated password into the .my.cnf file.

# vim /root/.my.cnf

[client]
password = yournewpassword