I recently had to setup a server that was half-assed configured, i.e. MySQL was setup but the guy who did it forgot to write down the password. As you might know, adding a new database, dropping tables, etc. is pretty much impossible when you don’t have the MySQL root password. Here’s a simple tutorial how to reset your MySQL root password.
- Stop the MySQL Server
/etc/init.d/mysql stop
- Start the MySQL Server with –skip-grant-tables option. Be careful that MySQL is not accessible from the outside since this option allows everybody to login without username/password
mysqld_safe --skip-grant-tables
- Login to MySQL with a simple command:
mysql
- Use this command to set a new password (MY_NEW_PASSWORD):
UPDATE mysql.user SET Password=PASSWORD('MY_NEW_PASSWORD') WHERE User='root';
FLUSH PRIVILEGES; - Restart MySQL Server
/etc/init.d/mysql restart
- Login to your MySQL Server using the newly defined password
mysql -uroot -pMY_NEW_PASSWORD
This tutorial assumes that you are able to start/stop MySQL on your system. I hope it is of any help to people in a similar situation.