How to reset the mysql root password
You can reset the root password for your mysql server if you lost the password and no longer remember.
Even I happened to forget my password and do not remember it, and I had some pretty major databases …
-
Mysql server under windows
In command prompt (start->run->CMD) navigate to your “bin” folder of your mysql server. here you need to run the following commands
1 |
mysqld --skip-grant-tables |
Leave that window open and open a new command prompt window and run the following commands:
1 2 3 4 5 |
mysql -u root mysql> use mysql; mysql> update user set password=PASSWORD("PAROLA-NOUA") where User='root'; mysql> flush privileges; mysql> quit |
And that’s it, you can now login using the new mysql password
-
Mysql server on linux
For starters you need to login to your SSH and stop the mysql server:
1 |
/etc/init.d/mysql stop |
Then start the server without privileges:
1 |
mysqld_safe --skip-grant-tables & |
We are going to login as root but with no password:
1 |
mysql -u root |
Now to actually change the password:
1 2 3 4 |
mysql> use mysql; mysql> update user set password=PASSWORD("PAROLA-NOUA") where User='root'; mysql> flush privileges; mysql> quit |
Finaly restart the mysql service:
1 |
/etc/init.d/mysql stop; sleep 5; /etc/init.d/mysql start |
That’s it, you can now use the new password:
1 |
mysql -u root -p |