Tuesday, September 20, 2011

MySQL - How to reset the MySQL root password?

If you forget the MySQL root password and are locked out of the system, don't panic - there's still hope! All you need to do is follow the simple steps outlined in the following:


  1. Shut down MySQL, and then restart it.When restarting MySQL, add the following two options to the mysql_safe command line:

    $ /usr/local/mysql/bin/mysqld_safe --skip-grant-tables --skip-networking &

  2. Log in to the MySQL server as root using the MySQL client. Because MySQL was started without the grant tables, you can use an empty password to gain access.$ /usr/local/bin/mysql -u root

  3. Once logged in, set a new password for the root account by directly modifying the grant tables as follows:

    mysql > UPDATE mysql.user SET Password=PASSWORD('new-password') WHERE User='root';
    Query OK, 1 row affected (0.06 sec)

  4. Log out of MySQL, and then shut down and restart the server in the normal manner. You should now be able to log in as root user, with the new password you set in Step 3.
Hope this post helps.

No comments:

Post a Comment