In the process of using the MySQL database, it is often necessary to modify the password of the root user. Under macOS, to change the password of the MySQL root user, you can follow the steps below.
Enter the following command to stop the MySQL service:
sudo /usr/local/mysql/support-files /mysql.server stop
The method to start the MySQL server and ignore the permission table is as follows:
sudo mysqld_safe --skip-grant-tables
Open another terminal window , and enter the following command to connect to the MySQL server:
mysql -u root
Enter the following command to change the password of the root user:
use mysql; update user set authentication_string=password('新密码') where user='root'; flush privileges;
Among them, the new password is the one you want to set password. It should be noted that in MySQL 5.7 and newer versions, the default password policy for the root user has been upgraded, and a password that meets the requirements needs to be set. Otherwise, an error may be reported.
Finally, exit the MySQL server and enter the following command:
exit
Stop the MySQL service and enter the following command:
sudo /usr/local/mysql/support-files/mysql.server stop
The above are the detailed steps for changing the MySQL root user password under macOS. If your MySQL version is different, the steps may be slightly different. In short, changing the MySQL root user password is not difficult, as long as you follow the correct steps.
The above is the detailed content of How to change root password on mac mysql. For more information, please follow other related articles on the PHP Chinese website!