- 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 & - 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
- 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) - 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.