How to reset mysql root password on Ubuntu 12.04

Fast and easy!

$ sudo stop mysql
$ sudo -umysql mysqld_safe --skip-grant-tables &
$ mysql
mysql> UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
mysql> FLUSH PRIVILEGES;
$ sudo kill `cat /var/run/mysqld/mysqld.pid`
$ sudo start mysql

Enjoy your new mysql root password!

Advertisements