Scroll To Top

Have you forgotten your MySQL root password? I must admit I've been guilty of this a few times. Also helpful if you are working on a project where the previous developer or server admin has vanished. This article tells you how to reset your password.

You will need root access to the Linux box running the database.

Here are the steps to recover your MySQL password.

Step 1

Log in as root on the Linux server.

sudo su

Step 2

Create a file named mysql-init in your /root directory.

touch /root/mysql-init

Step 3

Place the following in your mysql-init file, be sure to change "myNEWpassword" to your new password:

UPDATE mysql.user SET Password=PASSWORD('myNEWpassword') WHERE User='root';

Note: ensure UPDATE and FLUSH are on their own lines.

Step 4

Turn off your mysql service.

sudo service mysql stop

Step 5

Run your mysql-init

mysqld_safe --user=mysql --init-file=/root/mysql-init &

Note: Make sure the user is set to your mysql user.

Step 6

sudo service mysql restart

After the server has started successfully, delete your mysql-init for security.

rm /root/mysql-init