database

How do I reset the MySQL root password on my Unix server?

If you lose or forget the root password for your MySQL database, you can use the procedure below to reset it.

1. Log on to your server as the user that the mysqld server runs as (for example, mysql).

2. Stop MySQL using the init script or kill -9 the mysqld PID.

3. Create a text file containing the following statements. Replace the password with the password that you want to use.

UPDATE mysql.user SET Password=PASSWORD(‘MyNewPass’) WHERE User=’root’;
FLUSH PRIVILEGES;

NOTE: Make sure the UPDATE and FLUSH statements are on separate lines. The UPDATE statement resets the password for all root accounts, and the FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.

4. Save the file. The file contains the password, so it should not be saved where it can be read by other users.

5. Start the MySQL server with the special –init-file option:

shell> mysqld_safe –init-file=/root/mysql-init &

The server executes the contents of the file specified by the –init-file option at startup. This will change each root account password.

6. After the server has started successfully, delete the file you created in the previous steps (Ex. /root/mysql-init).

7. You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally.

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

To Top