Skip to content

Instantly share code, notes, and snippets.

@dieunb
Last active March 7, 2018 07:42
Show Gist options
  • Select an option

  • Save dieunb/6c6d58214ec9cc8fbfde6e94e8489027 to your computer and use it in GitHub Desktop.

Select an option

Save dieunb/6c6d58214ec9cc8fbfde6e94e8489027 to your computer and use it in GitHub Desktop.
Reset MySQL root password on Macos
If you don't remember the password you set for root and need to reset it, follow these steps:
Stop the mysqld server, this varies per install
Run the server in safe mode with privilege bypass
sudo mysqld_safe --skip-grant-tables;
In a new window connect to the database, set a new password and flush the permissions & quit:
mysql -u root
For MySQL older than MySQL 5.7 use:
UPDATE mysql.user SET Password=PASSWORD('your-password') WHERE User='root';
For MySQL 5.7+ use:
USE mysql;
UPDATE mysql.user SET authentication_string=PASSWORD("your-password") WHERE User='root';
Refresh and quit:
FLUSH PRIVILEGES;
\q
mysql> UPDATE mysql.user SET Password=PASSWORD('your_new_password')
WHERE User='root';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> SET PASSWORD = PASSWORD('your_new_password');
Query OK, 0 rows affected, 1 warning (0.01 sec)
Stop the safe mode server and start your regular server back. The new password should work now. Worked like a charm for me :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment