One of my colleagues just installed MySQL on his MAC Mini, and forgot what password he set at the beginning. However, he needed to use the local MySQL database recently, so HE searched a lot of methods on the Internet and none of them worked, but he didn’t want to delete them and reinstall them. Finally, I found a correct method, and here is the solution to share.


1. Restart the MySQL server

  • Open theSystem PreferencesMySQLAnd then clickStop MySQL ServerShut downMySQLThe server.

  • Shut downMySQLAfter the server, open the terminal and enter the following commandMySQLDirectory.
cd /usr/local/mysql/bin
Copy the code
  • Enter the following command to obtain permission.
sudo su
Copy the code
  • Then enter the following command to restartMySQLThe server.
./mysqld_safe --skip-grant-tables &
Copy the code

2. Change the MySQL password

  • Don’t turn off that terminal. Press itcommand + NOpen another terminal window and enter the following command to configure the short command.
alias mysql=/usr/local/mysql/bin/mysql
Copy the code
  • Then enter the following commandMySQLCommand mode.
mysql
Copy the code
  • Enter the following commandMySQLThe database.
use mysql
Copy the code
  • Then enter the following command to obtain permissions.
flush privileges;
Copy the code
  • You can now modify yours by typing the following commandMySQLThe password,xxxFill in your new password.
set password for 'root'@'localhost'=password('xxx');
Copy the code

3. Verify the new MySQL password

  • Open the terminal and run the following command to log inMySQLThe database.
/usr/local/mysql/bin/mysql -u root -p
Copy the code
  • Then enter your new password ifMySQLIf the database is connected, the password is successfully changed.


Finally, I attached the reference address of this article and gave the blogger a thumbup. I found so many methods, but this one is reliable, so I shared it so that more people can see it, hoping to help people to walk less pits.

In the future, you will be grateful for your hard work now, and wish you and your readers a better way of development.

My portal: blog, Book, Twitter, GitHub.