Mac下經過Homebrew安裝MySQL

最近重裝了mac系統,全部經常使用的軟件都須要從新安裝一遍,無疑安裝一個brew是個很好的選擇,關於brew是什麼,怎麼安裝建議去brew官網查看,附上地址:brew官網html

安裝完成以後,安裝其餘的軟件就特別方便了。mysql

執行:sql

brew install mysql

等成功安裝完成,結果想要登陸的時候報了個錯誤:數據庫

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

網上搜索了半天,找到解決方案,依次執行bash

unset TMPDIR

```bash
mysql_install_db --verbose --user=root --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmpsocket


接下來啓動mysql ```bash mysql.server start

啓動後就能夠登陸了,登陸命令爲:code

mysql -uroot -p

而後提示輸入數據庫密碼,初始沒有密碼的狀況下直接回車,就進入數據庫了server

若是想設置開機啓動,執行下面的命令htm

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

大功告成~homebrew

相關文章
相關標籤/搜索