Reset MySQL root password on Linux
Sometimes it becomes necessary to restore the password of the MySQL database administrator (the root of a user or another superuser, for example, if the superuser is not root or root has been deleted) on a server running Linux. Below, we will take a step-by-step look at how to reset the MySQL admin password.
How to reset MySQL root password on Linux
1. Stop MySQL by running the command below:
2. We start the MySQL server with special parameters (without privilege checking):
/usr/bin/mysqld_safe --skip-grant-tables --user=root &
3. Run the MySQL client:
mysql -u root
4. Set a new password for the root user to execute this SQL query below:
Where password_for_root - this is the new password for the root MySQL user.
mysql>UPDATE mysql.user SET Password=PASSWORD('password_for_root') WHERE User='root';
5. After that, reset the privileges with the command:
6. And exit the MySQL client:
7. After that need to restart the MySQL server in normal mode by running the command:
These are all the steps necessary to reset the root password in MySQL. After that, you can use the new root password to connect.
Latest Blog Posts