It happens that sometimes (after 2 days 🙂 ) you forget the password for your root user on MySQL, well there are few steps to perform to recover it.

This was performed on version:

$ mysql -V
mysql  Ver 14.14 Distrib 5.1.61, for debian-linux-gnu (x86_64) using readline 6.2

The following steps need to be performed as root user, so either login with it or use sudo.

Step 1:Stop the MySQL service

$ sudo /etc/init.d/mysql stop

Step 2: Start the MySQL server without password

$ sudo mysqld_safe --skip-grant-tables &

Step 3: Connect to the MySQL server using the MySQL client

$ sudo mysql -u root

Step 4: Change the password for the root user

mysql> use mysql;
Database changed
mysql> update user set password=PASSWORD("YOUR_NEW_PASS") where user = 'root';
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3  Changed: 3  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

Step 5: Stop the MySQL server again

$ sudo /etc/init.d/mysql stop

Step 6: Start the MySQL server (normally) and test the new password

$ sudo /etc/init.d/mysql start
$ sudo mysql -u root -p

 

This should also work on Windows as well, you will just need to use different commands for start/stop of the MySQL deamon.