How To: Reset MySQL Root Password
If you have forgotten or lost your MySQL root password you can still recover it. In order to reset your MySQL root password, you’ll need to have root access to the server. If you don’t, you probably shouldn’t have root access to MySQL either.
Reset MySQL Root Password
Login as root to your server/machine/box
Stop your current MySQL daemon (/etc/init.d/mysql stop)
Enter
mysqld_safe --skip-grant-tablesThis will load MySQL daemon without checking for authorization against the Grant Tables. You’ll be allowed to do whatever you need as root, including resetting the password.
Type
mysql --user=root mysqlThis will log you into MySQL as the user root using the table “mysql” – where grant tables are stored.
And then
UPDATE USER SET Password=PASSWORD('your-password') WHERE USER='root';
FLUSH privileges;
exit;Replace your-password above with whatever password you would like to reset root MySQL to.
Restart mysql (usually /etc/init.d/mysql restart)
Login again using your new root password
mysql -u root -p
Enter Password:
Social Links
Thank you for taking the time to read this post. We hope you've enjoyed the
content here. Please feel free to use the links below to share this post with others.