This page looks best with JavaScript enabled

Reset mysql password

 ·  🎃 kr0m

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

/etc/init.d/mysql stop

Start MySQL skipping authentication

/usr/bin/mysqld_safe --skip-grant-tables &

Access MySQL

mysql --user=root 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

kill %1

Start regularly

/etc/init.d/mysql start

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.

emerge --config =dev-db/mysql-VERSION
If you liked the article, you can treat me to a RedBull here