In recent years, more and more people use Mac. At the same time, MySQL database is also widely used in various applications. Although the installation and configuration of MySQL on Mac is relatively simple, it is also very common to encounter the need to change the password when using MySQL frequently. This article will introduce how to change the MySQL password on Mac.
Step 1: Enter the terminal interface of MySQL
First, we need to enter the terminal interface of MySQL. We can open the application in the Mac terminal and enter the following command:
mysql -u root -p
Of course, when entering the above command, you need to ensure that the MySQL service is turned on. At this time, you need to enter the password of the MySQL super user root. If the password entered is correct, we can enter the MySQL terminal interface.
Step 2: Modify MySQL password
After entering the MySQL terminal interface, we can use the following command to modify the MySQL password:
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
In the above command, new The password can be any new password we want to set. It should be noted that the command to change the password needs to use a semicolon ";" as the end mark.
Step 3: Refresh the MySQL permission table
After modifying the MySQL password, we need to refresh the MySQL permission table so that MySQL can read the new user permission information. We can use the following command to refresh MySQL's permission table:
FLUSH PRIVILEGES;
When we execute the above command, we can see that MySQL has successfully refreshed the permission table.
Step 4: Exit the MySQL terminal interface
After completing the above command, we do not need to stay in the MySQL terminal interface. We can use the following command to exit the MySQL terminal interface:
quit;
At this time, we will return to the Mac terminal interface.
Summary:
It is not difficult to change the MySQL password on Mac, just follow the above steps. If we often need to change the MySQL password, we can record the above steps in common commands, so that we can quickly change the MySQL password in the future. At the same time, we need to ensure that the passwords we set are safe to avoid problems such as data leakage.
The above is the detailed content of How to change mysql password on mac. For more information, please follow other related articles on the PHP Chinese website!