Linux : How to reset MySQL root password

By | July 26, 2012

Lost your root password for MySQL? Follow this simple procedure to reset it. Of course, you need at least root access level on your operating system to proceed.

1. Stop MySQL database server :

/etc/init.d/mysql stop

2. Start MySQL with “skip grant table” option :

mysqld_safe --skip-grant-tables  &

WARNING! This is VERY insecure – while running with this mode, everyone have free access to the whole database server. I do recommend to do it offline or at least block any remote MySQL connection (TCP-3306). You can as well start it without networking support with command :

mysqld_safe --skip-grant-tables --skip-networking &

3. Log into MySQL :

mysql -u root -p

4. Set new password :

mysql> use mysql;
mysql> update user set password=PASSWORD("NEW_PASSWORD") where user="root";
mysql> flush privileges;
mysql> Ctrl+D

5. Stop MySQL :

/etc/init.d/mysql stop

6. Start MySQL normally :

/etc/init.d/mysql start