What should I do if MySQL forgets the initial password under MAC

  • 2021-07-01 08:26:57
  • OfStack

MAC MySQL forget the initial password solution to share with you, for your reference, the specific content is as follows

After installing dmg of MySQL from official website.

1 Set the mysql command

Input from the terminal


mysql --version

If the version number is displayed, it indicates normal; If command not found is displayed, link the installation path as follows


cd /usr/local/bin/
sudo ln -fs /usr/local/mysql/bin/mysql mysql

Shutdown the mysql service


sudo /usr/local/mysql/support-files/mysql.server stop

3 Safe Mode Startup mysql


sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables

After that, open system preferences, select mysql, and you will find mysql service and restart.

4 Back to the terminal

Command + N reopen 1 terminal, enter


Mysql -u root

At this time, you can directly enter mysql without password, and you can modify any password.

5 Change the password at the new terminal


mysql> FLUSH PRIVILEGES;
mysql> SET PASSWORD FOR root@'localhost' = PASSWORD('123');
//  You can also change other passwords 
//  Last refresh 
mysql> FLUSH PRIVILEGES;

After that, you can log in to mysql with your new password.

For more information about MySQL cryptographic operations, please refer to the topic: MySQL cryptographic operations summary.


Related articles: