First of all, go to the official website to download MySQL and select the Mac version of the DMG format file.
The official website address is: dev.mysql.com/downloads/mysql/5.7.html
Then after downloading, directly double-click the corresponding dmg format file to install it. Next, we can first look at how to start MySQL in the system preferences. First open the system preferences, and then select MySQL:
At this time, you can see the MySQL start button Start MySQL Server, we can click this button, and then start MySQL locally.
At this time MySQL started successfully, but this is not the way we want, we want to start from the command line, so we first open the terminal:
then use the vi command to edit the ~/.bash_profile file:
change the following command Add it, then save and close the file:
export PATH=$PATH:/usr/local/mysql/bin
export PATH=$PATH:/usr/local/mysql/support-files
and then refresh through the source command to make the command we set to take effect: At
this time, we can start and close MySQL on the command line.
Start command: sudo mysql.server start
Close command: sudo mysql.server stop
Check whether it has been started: sudo mysql.server status