Reset 'root' password in MySQL (Mac OS X)

Sergio's picture

1. Turn off the MySQL server:
sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop

2. Open two terminal tabs/windows. In first terminal window enter the following command:
sudo /usr/local/mysql/bin/mysqld_safe –-skip-grant-tables

3. In second terminal window launch the admin console by entering:
/usr/local/mysql/bin/mysql mysql

4. Set the new password by executing the following queries (maintaining the syntax please):
USE mysql;
UPDATE mysql.user SET Password=PASSWORD('your_password') WHERE Host='localhost' AND User='root';

Note: In the case if host setting is not set you could execute the following query:
UPDATE mysql.user SET Host='localhost' WHERE User='root';

5. Execute the query: FLUSH PRIVILEGES;

6. Stop server: sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop

7. Start server: sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

8. quit;

Alternatively, to delete or nullify the password, run queries in the same sequence but setting the password as NULL:
USE mysql;
UPDATE mysql.user SET Password=null WHERE User='root';

That's it.