mac 下安裝mysql,mac安裝mysql

來源:互聯網
上載者:User

mac 下安裝mysql,mac安裝mysql

mac下安裝mysql有兩種方法,一種是直接去http://dev.mysql.com/downloads/mysql/ 下載個dmg的安裝包,然後一路安裝即可。但是這裡有個問題,由於mac的檔案系統和linux還是有區別,導致安裝後mysql -u root -p登陸時會報錯:

ERROR 2002 (HY000): Can not connect to local MySQL server through socket '/tmp/mysql.sock' (2)

網上有具體的解決方案,不過我一直沒成功。所以果斷採取了第二種方法用brew 安裝

brew是mac的一個軟體管理器,類似於linux的apt-get install。首先安裝brew ,進入http://brew.sh/官網,在終端裡運行

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
即可安裝成功。

然後就是使用blew安裝mysql的命令了,依次執行下面的命令,其中有些過程安裝比較慢,請耐心等待。

 brew install mysql
安裝完成後,登陸依然報這個錯。

ERROR 2002 (HY000): Can not connect to local MySQL server through socket '/tmp/mysql.sock' (2)
接下來依次執行下列命令:

unset TMPDIR
mysql_install_db --verbose --user=root --basedir="$(brew --prefix mysql)"--datadir=/usr/local/var/mysql --tmpdir=/tmp

mysql.server start
然後就可以登陸了,登陸命令為:

mysql -uroot -p
如果想設定開機啟動,執行下面命令:

mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/mysql/5.6.16/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/ #5.6.16是資料庫版本號碼,根據你當時所安裝的版本號碼自己修改
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
至此,mac成功安裝了mysql。錯誤的地方歡迎交流指正。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.