MySQL: How to reset the root account
Published:
I just managed to mess up the MySQL root account. Not a smart idea. After some MySQL manual reading and some serious Google-Fu, I figured out how to fix it.
- Stop the mysql server
- Add the following to the
my.cnf
file
[mysqld]
skip-grant-tables
- Start the mysql server
- Start a mysql client and run the following query
REPLACE INTO mysql.user VALUES ('localhost','root',PASSWORD('blah'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
- Quit the mysql client
- Stop the mysql server
- Remove what we added to
my.cnf
in step 2 - Restart the mysql server
Tadaa.