I recently needed the MySQL root password on a server of mine to complete a task but had misplaced it and was unable to locate it. Thinking that I had seriously goofed up I was worried. Luckily, resetting the password was surprisingly simple.
All you will need is root access to your VM and about two minutes of time.
First things first, you'll need to shutdown MySQL temporarily:
service mysql stopOnce the service has shutdown, you can proceed to restart it with the following:
mysqld_safe --skip-grant-tables &Now you should be able to login as the MySQL root user without being prompted for a MySQL password. Give it a whirl:
mysql -u rootYou should see the familiar MySQL prompt now.
To reset the password you can follow the commands below:
mysql> use mysql;
mysql> update user set password=PASSWORD("MyNewMySQLPassword") where User='root';
mysql> flush privileges;
mysql> quit(Obviously replacing "MyNewMySQLPassword" with a proper password)
Restart MySQL:
service mysql restartCheck that your new MySQL password works, it should:
mysql -u root -p
That's it.
All you will need is root access to your VM and about two minutes of time.
First things first, you'll need to shutdown MySQL temporarily:
service mysql stopOnce the service has shutdown, you can proceed to restart it with the following:
mysqld_safe --skip-grant-tables &Now you should be able to login as the MySQL root user without being prompted for a MySQL password. Give it a whirl:
mysql -u rootYou should see the familiar MySQL prompt now.
To reset the password you can follow the commands below:
mysql> use mysql;
mysql> update user set password=PASSWORD("MyNewMySQLPassword") where User='root';
mysql> flush privileges;
mysql> quit(Obviously replacing "MyNewMySQLPassword" with a proper password)
Restart MySQL:
service mysql restartCheck that your new MySQL password works, it should:
mysql -u root -p
That's it.