MySQL Reset Root Password

October 14, 20191 min readUpdated 10/14/2020

Stop MySQL server

sudo systemctl stop mysql

// OR

/etc/init.d/mysql stop

Start MySQL server without loading grant table

The ampersand & at the end of the command above will cause the program to run in the background, so you can continue to use the shell.

When the --skip-grant-tables option is used, anyone can to connect to the database server without a password and with all privileges granted.

sudo mysqld_safe --skip-grant-tables &

Once safe mode has started up, log into MySQL and when prompted, use your standard root password.

mysql -u root mysql

Update user root password.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MY_NEW_PASSWORD';

If the above command does not work, try this.

UPDATE mysql.user SET authentication_string = PASSWORD('MY_NEW_PASSWORD') WHERE User = 'root' AND Host = 'localhost';

Be sure to reload everything.

FLUSH PRIVILEGES;

Now you have a new password “MY_NEW_PASSWORD”

Stop and restart the server normally

Stop server

mysqladmin -u root -p shutdown

Start server

sudo systemctl start mysql

//OR

/etc/init.d/mysql start

Verify your password change

mysql -u root -p

Enter your password. If you get in then you password has been successfully reset.