There are two ways you can go about resetting the MySQL root password.

Option 1

Run the following commands:

# /etc/init.d/mysqld stop
# mysqld_safe –skip-grant-tables


Now you will login to to MySQL and run the following commands:

mysql> UPDATE mysql.user SET Password=PASSWORD(‘newpassword’) WHERE User=’root’ and Host=’localhost’;
mysql> flush privileges;


Quit MySQL and run the following commands:


# killall mysqld
# /etc/init.d/mysqld star


Option 2

edit /etc/my.cnf and add the following under the [mysqld] section:

skip-grant-tables

restart MySQL


# /etc/init.d/mysqld restart

Login to mysql and run the following commands:


mysql> UPDATE mysql.user SET Password=PASSWORD(‘newpassword’) WHERE User=’root’ and Host=’localhost’;
mysql> flush privileges;

Quit MySQL and remove the line ’skip-grant-tables’ from my.cnf and then restart MySQL.

One Response to “MySQL – Resetting root’s Password”
  1. jak-hacl says:

    These are some awful ways to reset the password. You should look into another way to reset the root password as these will leave your system temporarily vulnerable.

  2.  
Leave a Reply