What if you’ve forgotten your MySQL root user password? This could be quite the predicament … had the developers not thought of that eventuality. In order to recover the password, you simply have to follow these steps:
- Stop the current MySQL server process
- Start the MySQL server with the command sudo mysqld_safe –skip-grant-tables –skip-networking &
- Connect to the MySQL server as the root user with the command mysql -u root
At this point, you need to issue the following MySQL commands to reset the root password:
mysql> use mysql; mysql> update user set authentication_string=password('NEWPASSWORD') where user='root'; mysql> flush privileges; mysql> quit
After this you can shutdown the mysql-server and start it the normal way.
(!) on very old mysql databases the “authentication_string” field is called “Password”. so the command looks like follows:
mysql> update user set Password=password('NEWPASSWORD') where user='root';
source: [link]