Resetting the Root Password - MySQL

Overview

In the case where the password for the "root" account for a MySQL instance running on a Linux machine is lost, the following procedure will allow you to reset the password.

Procedure

The following procedure is adapted from https://www.howtoforge.com/setting-changing-resetting-mysql-root-passwords

1. Connect to the Linux instance via Putty

2. Stop the MySQL instance
sudo service mysqld stop

Or less commonly...

sudo /etc/init.d/mysqld stop

3. Start the MySQL server/daemon so it won't prompt for a password.

sudo mysqld_safe --skip-grant-tables &

4. Log into MySQL as the "root" user

mysql -u root

5. Change the password.

use mysql;
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
flush privileges;
quit

6. Restart MySQL
sudo service mysqld stop
sudo service mysqld start

Or less commonly...

sudo /etc/init.d/mysqld stop
sudo /etc/init.d/mysqld start

7. Test

mysql -u root -p