Reset MySQL root Password
To reset MySQL root user’s password, follow the following steps.
- Terminate all running instances of MySQL server. You can do that either via the RC script (/etc/init.d/<script_name> stop or /user/local/etc/rc.d/<script_name> stop for FreeBSD) or using the tools like kill and pkill. To use kill or pkill, you will have to use ps or pgrep to find out the process names or process ID (PID).
Using the RC script to do a proper shutdown is safer than using kill or pkill.
- Start the MySQL server in safe mode
mysqld_safe --skip-grant-tables --user=mysql - On another terminal, login to the MySQL server as the root user
mysql -u root
On the MySQL prompt, run the following commandsUSE mysql;
UPDATE user SET Password=PASSWORD('New-Password') WHERE User='root';
FLUSH PRIVILEGES;
\q - Terminate all MySQL server processes. At the least you should have two MySQL processes – mysqld_safe and mysql.
- Start your MySQL server normally using the RC script. Now, you can login as root with the new password.