Skip to content

Instantly share code, notes, and snippets.

@emotality
Last active April 7, 2021 19:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save emotality/5861b2d30575feb3bf510abeedeec4a8 to your computer and use it in GitHub Desktop.
Save emotality/5861b2d30575feb3bf510abeedeec4a8 to your computer and use it in GitHub Desktop.
Reset MySQL Password on macOS

Reset MySQL Password on macOS

1. Stop all MySQL services

Note: It HAS to be closed before this will work!

First, go to System Preferences, go to MySQL, and Stop MySQL Server.

$ launchctl unload /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
$ killall mysql mysqld _mysql
$ ps aux | grep mysql

If you see mysqld or _mysql somewhere, take the number next to it, that is the process id. Now kill the process:

$ sudo kill -9 <PID>
# example: sudo kill -9 1234
# Kill the process with the same user that started it, above we used sudo for root

If you cant close mysqld, you would need to restart your system and then restart Step 1.

2. Reset password

$ sudo mysqld_safe --skip-grant-tables

If you see Starting mysqld daemon with databases from.. then it succeeded!

Open a new Terminal window while this window is running, do not stop this process or close window!

$ mysql -u root

Select mysql database:

mysql> USE mysql;

Reset Password:

mysql> UPDATE user SET Password=PASSWORD("NEW_PASSWORD") WHERE User='root';
mysql> FLUSH PRIVILEGES;

If that didnt work, try resetting authentication_string:

mysql> UPDATE user SET authentication_string=PASSWORD("NEW_PASSWORD") WHERE User='root';
mysql> FLUSH PRIVILEGES;

Exit when done!

mysql> exit;

You can now close your first Terminal window to close the mysqld_safe process.

Go to System Preferences and start your MySQL Server.

You can now log in with your new credentials:

$ mysql -u root -p
# enter new password

If this didn't work, continue with steps.

3. Delete MySQL

Go root with:

$ sudo su
# enter your system password

Delete MySQL:

$ rm -rf /usr/local/mysql*
$ rm -rf /Library/StartupItems/MySQL*
$ rm -rf /Library/PreferencePanes/MySQL*
$ rm -rf ~/Library/PreferencePanes/MySQL*
$ rm -rf /Library/Receipts/mysql*
$ rm -rf /Library/Receipts/MySQL*
$ rm -rf /private/var/db/receipts/*mysql*

Restart your system to be safe!

4. Download MySQL

5. Install MySQL

NOTE: COPY THE PASSWORD AND KEEP IT IN TEXT FILE AND KEEP IT OPEN

6. Log in

$ mysql -u root -p
# enter given password

If that failed, try changing it with:

$ /usr/local/mysql/bin/mysqladmin -u root -p'TEMP_PASSWORD' password 'NEW_PASSWORD'

If that failed, go back to Step 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment