Forgetting the password of a MySQL server can be a big problem, especially in those moments when the server has problems and we need immediate access to the database. For these cases where we cannot waste time, the fastest way is to reset the password and solve the problem. This is not as pretty as it seems since it involves a service stop, but at least we will regain control over our database.
The reset procedure consists of several steps:
Stop MySQL
Start MySQL skipping authentication
Access MySQL
Update the root password
UPDATE user SET Password=PASSWORD('new-password-here') WHERE User='root';
flush privileges;
exit
Kill MySQL in skip-grants mode
Start regularly
Now we should be able to access our MySQL without any problem ;)
NOTE: If we have had to take extreme measures and have deleted /var/lib/mysql, we must first reinstall the basic MySQL structure.