The Solution of Forgetting the Password of root User of Mysql under Mac
- 2021-07-10 21:00:23
- OfStack
I haven't got 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 open the mysql service in a secure way, and then update the password table.
First we're going to shut down the original mysql service, System Preferences-- > MySQL- > Stop MySQL Server
Then open 1 Terminal, open mysql in safe mode, and do not need a password when connecting
sudo mysqld_safe --skip-grant-tables
Then open another Terminal and update the password
mysql -u root
UPDATE mysql.user SET authentication_string=PASSWORD('your_new_password') WHERE User='root';
FLUSH PRIVILEGES;
In the above format, you only need to modify your_new_password
If Mysql is prior to V 5.7. 9, use the following sql statement
UPDATE mysql.user SET Password=PASSWORD('your_new_password') WHERE User='root';
Finally, restart Mysql and try 1
mysql -uroot -pyour_new_password
Be crowned with success! ! ! !
In addition, attach the solution of netizens:
step1:
Turn off mysql service: Apple- > System Preferences- > The bottom point mysql closes the mysql service in the pop-up page (click stop mysql server)
step2:
Enter terminal input:
cd /usr/local/mysql/bin/
Login Administrator Permissions after Enter
sudo su
Enter and enter the following command to disable mysql authentication
./mysqld_safe --skip-grant-tables &
mysql will restart automatically after carriage return (the status of mysql in preferences will change to running)
step3:
Enter commands./mysql
Enter, enter the command
FLUSH PRIVILEGES;
Enter, enter the command
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('你的新密码');
After the above steps are completed, the password has been modified successfully, and now you can log in to mysql with the newly set password.