Reset MySQL Root Password on MAC

Jenny
2 min readDec 22, 2020

--

MySQL verison: 8.0.22

Step1. Stop MySQL Server

Make sure the status of MySQL Server located in macOS System Preferences Panel is in red(means stopped). If it is in green(means running),you must top it by clicking the ‘Stop MySQL Server’ button.

Green means the MySQL Server is running

*If Stop MySQL Server has no response, try:

/usr/local/mysql/support-files/mysql.server stop
Now, the MySQL Server has stopped

Step2. Skip grant tables in Terminal

cd /usr/local/mysql/binsudo ./mysqld_safe --skip-grant-tables

Input system password, not MySQL’s.

Step3. Alter root password in Terminal

Open another terminal window,

cd /usr/local/mysql/bin./mysql -u rootmysql> FLUSH PRIVILEGES;mysql> ALTER USER 'root'@'localhost' IDENTIFIED by 'new_password';

If it occurs errors like :

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

We need to adjust the values of the password policy and length.

The new version MySQL doesn’t support the password function anymore. Instead of using ‘validate_password_policy’, you should imply ‘validate_password.policy’.

“The validate_password.policy value can be specified using numeric values 0, 1, 2, or the corresponding symbolic values LOW, MEDIUM, STRONG. The following table describes the tests performed for each policy. For the length test, the required length is the value of the validate_password.length system variable. Similarly, the required values for the other tests are given by other validate_password.xxx variables.”

For example,

#set password level
mysql> set global validate_password.policy=0;
#set password length
mysql> set global validate_password.length=1;

Then, you can set the new password.

Other, ways to start, stop, and restart MySQL database server via the command line:

#start MySQL Server
sudo /usr/local/MySQL/support-files/mysql.server start
#stop MySQL Server
sudo /usr/local/mysql/support-files/mysql.server stop
#restart MySQL Server
sudo /usr/local/mysql/support-files/mysql.server restart

--

--