Mac MySQL Reset Root Password Tutorial

  • 2021-10-16 05:18:13
  • OfStack

Affirmation: This password reset can directly reset the password of MySQL installed by Homebrew, and the corresponding installation directory needs to be switched for MySQL installed by other methods.

After installing MySQL for too long, you will forget your password. Here, I summarize how to reset your local MySQL Root password when you forget your password.

All operations are done in the Mac terminal (Terminal).

Stop services and processes:


brew services stop mysql

Enter the folder:


cd /usr/local/opt/mysql/bin

Execute ultra vires order (mysql):


mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

Enter the MySQL command using (mysql):


mysql -u root mysql

Perform the change of password code:


UPDATE mysql.user
     SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
     WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;

Exit:

quit;

Restart:


brew services restart mysql
mysql.server restart

New password login:


mysql -u root -p

Summarize


Related articles: