When using a Mac computer to build a MySQL database, sometimes you need to change the password of the MySQL database. At this time, you need some specific steps. Next, I will introduce how to change the password of the MySQL database on Mac.
Step one: Log in to MySQL
First we need to log in to MySQL to change the password. Enter the following command in the Mac terminal:
mysql -u root -p
Among them, after "-u" Enter the user name. The default user name here is root; "-p" means password. After executing this command, you will be asked to enter the MySQL password.
Enter the password and press Enter to enter the MySQL database.
Step 2: Change the password
After logging in to MySQL, we need to execute the following command to change the password of the MySQL database:
use mysql;
This command is used to switch to MySQL System tables, used for user management operations. Then, enter the following command:
UPDATE user SET password=PASSWORD("newpassword") WHERE user='root';
Among them, "newpassword" is the new password you want to change. After entering the command, you need to press Enter to execute.
At this point you have changed the password of the MySQL database, but to make it effective, you need to execute the following command:
FLUSH PRIVILEGES;
This command will reload the authorization table in the current MySQL session and re- The new password cannot be used until loaded.
Step 3: Exit MySQL
After changing the password, we need to exit MySQL, enter the following command in the terminal:
quit
This command is used to exit the MySQL session, exit Then you can close the terminal.
Summary
It is not difficult to change the MySQL password. You only need to execute a few commands in the Mac terminal. However, in order to ensure the security of the MySQL database, we need to pay attention to the following points:
I hope this article can help everyone and become more comfortable when changing the MySQL password.
The above is the detailed content of mac change mysql password. For more information, please follow other related articles on the PHP Chinese website!