1. MySQL installation package download
If you haven't downloaded yet, please go to the official website to download
We can see that there are two dmg installation packages with different architectures. If you don’t know whether your computer is ARM or X86, you can open the terminal and enter: uname -a or uname -a | awk -F " " '{print $(NF -1)}' to see the following picture:
Here it shows that my computer is X86, choose the dmg package suitable for your computer and click Download on the right
Here you can directly select No thanks, just start my download without logging in to download.
2. Install MySQL
Double-click the downloaded dmg installation package to install
Continue all the way to Configuration
Here select Use Legacy Password Encryption and click Next
Click Finish to complete the installation
At this point, you can open the System Preferences and a MySQL icon will appear below (if it does not appear, you can log out of the Apple ID and reopen the System Preferences to see it)
Click to enter and you can see that the two small green marks on the left mean that MySQL is installed successfully
3. Configure MySQL
Let's test it first, enter mysql in the terminal, it will prompt that the command is not found
hello@wodeMacBook-Pro ~ % mysql
zsh: command not found: mysql
This means that we have not configured the environment yet, and edit the .zshrc configuration file through vim in the terminal
hello@wodeMacBook-Pro ~ % sudo vim ~/.zshrc
Click the i key to enter the edit mode, and add the following path to the configuration file:
export PATH=$PATH:/usr/local/mysql/bin
Then press esc to exit edit mode, enter: wq to save and exit
Then execute source ~/.zshrc on the terminal to make the configuration take effect
hello@wodeMacBook-Pro ~ % source ~/.zshrc
At this time, if you check the mysql version in the terminal, you can see that the version we installed can be found, indicating that the environment has been configured
hello@wodeMacBook-Pro ~ % mysql --version
mysql Ver 8.0.29 for macos12 on x86_64 (MySQL Community Server - GPL)
Now you can enter mysql -uroot -p in the terminal and enter the password to enter MySQL.
Briefly
-u: mysql user name, here directly write the user name root next to each other
-p: mysql password, if it is not written here, it will prompt for input, or it can be written directly next to p
At this point, the installation and configuration of MySQL on the Mac are all completed, and then you can start using MySQL.