In the process of using the Mac operating system, you may encounter situations where you need to change the MySQL database password. Below we will introduce how to change the MySQL database password on Mac.
If you are using Homebrew to install MySQL, the steps to change the MySQL password are as follows:
Step 1: Log in to MySQL
Enter the following command in the terminal:
mysql -u root -p
This will let you log in to the MySQL database using the root user. You will be asked for a password, if you have already set one, enter your MySQL password.
Step 2: Choose to use the MySQL database
After successfully logging in to MySQL, enter the following command:
use mysql
This will let you choose to use the MySQL database.
Step 3: Change the MySQL password
Enter the following command to change the MySQL password:
UPDATE user SET authentication_string=PASSWORD('这里是你的新密码') WHERE User='root';
This will change the root user's password to the new password you entered. Make sure to replace new password in the command with the new password you want to set.
Step 4: Refresh permissions
Enter the following command to refresh MySQL permissions:
FLUSH PRIVILEGES;
This will make your changes take effect.
Step 5: Exit MySQL
Enter:
quit
Exit the MySQL database.
If you are using MAMP to install MySQL, the steps to change the MySQL password are as follows:
Step 1: Open MAMP
Open the MAMP application in Applications.
Step 2: Open phpMyAdmin
Click "Open WebStart Page" and then select "phpMyAdmin".
Step 3: Log in to phpMyAdmin
Use the root user to log in to phpMyAdmin.
Step 4: Select to use MySQL database
Select "User Accounts" in the menu, and then click the root user.
Step 5: Change MySQL Password
Under "Change Password", enter your new password and save the changes.
Summary:
Whether you use Homebrew or MAMP to install MySQL, you can easily change the MySQL password. Just enter some commands in the terminal or phpMyAdmin and you're done. Remember to restart MySQL for the changes to take effect, and log in with your new password.
The above is the detailed content of mac mysql change password. For more information, please follow other related articles on the PHP Chinese website!