If you are a Mac user and you have forgotten your MySQL password, then don’t worry, you can reset your MySQL password by following these steps:
Open the Terminal application and stop the MySQL server using the following command:
sudo /usr/local/mysql/support-files/mysql.server stop
Use the following command to start the MySQL server and skip permission verification:
sudo mysqld_safe --skip-grant-tables
Note: Before starting the MySQL server , you will see a lot of screen output. Please do not close the Terminal application.
Open a new terminal application and use the following command to log in to the MySQL server:
mysql -u root
At this point, you have successfully logged into the MySQL server, and you should be able to see the MySQL prompt.
Now you can change your MySQL password using the following command:
UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root';
Please note to replace "new_password" with the new password you want to set.
After changing the password, use the following command to refresh the system permission table:
FLUSH PRIVILEGES;
Finally, use the following command to exit the MySQL server:
quit
Restart the MySQL server using the following command:
sudo /usr/local/mysql/support-files/mysql. server start
Now, you have successfully changed the MySQL password and can access the MySQL server normally.
The above is the detailed content of mac forgot mysql password. For more information, please follow other related articles on the PHP Chinese website!