You don’t need this tutorial if you have access to the
rootuser or another one with
The following instructions works for MySQL 5.7. You will need to stop the MySQL server and start it with
mysqld_safe with the option
sudo service mysql stop sudo mysqld_safe --skip-grant-tables & mysql -u root mysql
If you get an error on start, chances are there is no folder created for the
mysqld_safe executable to run, on my tests I was able to solve by doing:
sudo mkdir /var/run/mysqld sudo chown -R mysql:mysql /var/run/mysqld
And then trying to start the
mysqld_safe process again.
After this, the MySQL console will pop up, and you need to set up a new password for
root. The second line is necessary due to a MySQL bug #79027:
UPDATE mysql.user SET authentication_string=PASSWORD('mypassword') WHERE User='root'; UPDATE mysql.user SET plugin="mysql_native_password" WHERE User='root'; FLUSH PRIVILEGES;
Once finished, kill all MySQL processes and start the service again:
ps aux | grep mysql sudo kill -9 [pid] sudo service mysql start
Done, you have reset the
root password! Make sure to keep it safe this time around!
See something wrong in this tutorial? Please don’t hesitate to message me through the comments or the contact page.
3 thoughts on “How to reset your `root` password on your MySQL server”
Many thanks !!!