There are two ways to install MySQL under Mac, one is to go directly to http://dev.mysql.com/downloads/mysql/to download a DMG installation package, and then install it all the way. However, there is a problem, because the Mac file system and Linux are still different, resulting in the installation of Mysql-u root-p when landing will be error:
ERROR 2002 (HY000): Can not connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)
There are specific solutions on the Internet, but I haven't been successful. So decisively took the second method of installing with brew
Brew is a software manager for Mac, similar to the Linux apt-get install. First install brew, enter http://brew.sh/official website, run in terminal
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
can be installed successfully.
Then you use blew to install MySQL commands, and then execute the following command, some of which are slow to install, please wait patiently.
brew install mysql
After the installation is complete, the login still reported this error.
ERROR 2002 (HY000): Can not connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)
Next, execute the following commands in turn:
unset TMPDIR
mysql_install_db --verbose --user=root --basedir="$(brew --prefix mysql)"--datadir=/usr/local/var/mysql --tmpdir=/tmp
mysql.server start
Then you can log in, and the login command is:
mysql -uroot -p
If you want to set up boot, execute the following command:
mkdir-p ~/library/launchagents
cp/usr/local/cellar/mysql/5.6.16/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents /#5.6.16 is the database version number, which modifies the
according to the version number you installed at that time.
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
At this point, the MAC has successfully installed MySQL. The wrong place welcomes the communication.
Install MySQL under Mac