How to use the command line to start MySQL under Mac system

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

Insert picture description here
Insert picture description here
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:
Insert picture description here
Insert picture description here

At this time, you can see the MySQL start button Start MySQL Server, we can click this button, and then start MySQL locally.
Insert picture description here
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:
Insert picture description here
then use the vi command to edit the ~/.bash_profile file:
Insert picture description here
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
Insert picture description here
and then refresh through the source command to make the command we set to take effect: At
Insert picture description here
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
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_43248623/article/details/109132063