Solution for forgetting the Mysql root User Password on Mac, mysqlroot
I haven't gotten the mysql on my computer for a long time, and I forgot my password. But it doesn't matter. We can reset our password.
The principle is to enable the mysql service securely and then update the password-saving table.
First, we need to disable the original mysql service, System Preferences-> MySQL-> Stop MySQL Server
Then open a Terminal and enable mysql in safe mode. No Password is required during connection.
sudo mysqld_safe --skip-grant-tables
Then, run the Terminal command to update the password.
mysql -u rootUPDATE mysql.user SET authentication_string=PASSWORD('your_new_password') WHERE User='root';FLUSH PRIVILEGES;
In the preceding format, you only need to modify your_new_password.
If Mysql is a version earlier than V5.7.9, use the following SQL statement.
UPDATE mysql.user SET Password=PASSWORD('your_new_password') WHERE User='root';
Restart Mysql. Try it.
mysql -uroot -pyour_new_password
Success !!!!
The solution provided by netizens is as follows:
Step 1:
Close the mysql service: Apple-> system preference settings-> at the bottom of the page, click mysql to close the mysql service on the pop-up page (Click stop mysql server)
Step 2:
Enter terminal input:cd /usr/local/mysql/bin/
Enter and log on to the Administratorsudo su
Press enter and enter the following command to disable mysql verification../mysqld_safe --skip-grant-tables &
After you press enter, mysql will automatically restart (mysql in preference settings will change to running)
Step 3:
Enter the command./mysql
Press enter and enter the commandFLUSH PRIVILEGES;
Press enter and enter the commandSet password for 'root' @ 'localhost' = PASSWORD ('your new password ');
After completing the preceding steps, the password is successfully modified. Now you can use the new password to log on to mysql.