MySQL reset root password
How to reset a root MySQL password
Hello,
This time I share with you the faster and more secure method to reset the root password of MySQL.
This method is faster because the downtime is between 1 or 2 seconds (MySQL restart time) and it is more secure because the mysqld is not started without grants on the tables.
The steps are:
Create text file /var/lib/mysql/mysql-init with the sintaxis to reset the password for user root:
vim /var/lib/mysql/mysql-init
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
Add under the [mysqld] stanza on the file /etc/my.cnf:
init-file=/var/lib/mysql/mysql-init
Restart the mysqld service:
service mysqld restart
Remove the init-file line from /etc/my.cnf
Remove /var/lib/mysql/mysql-init
rm /var/lib/mysql/mysql-init
And after that, you can access again to your mysql instance.
😄