參考:(使用Homebrew安裝MySQL https://www.cnblogs.com/lidyan/p/6587718.html)html
安裝命令:python
brew install mysqlmysql
安裝完成以後,啓動mysql:web
mysql.server startsql
發現無此命令:app
command not foundwebapp
首先,檢查是不是安裝了。從新執行一遍:this
brew install mysqlserver
提示:htm
Warning: mysql 8.0.11 is already installed, it's just not linked
You can use `brew link mysql` to link this version.
而後網上查找解決方法,執行:
brew link mysql
報錯:
Linking /usr/local/Cellar/mysql/8.0.11...
Error: Could not symlink .
/usr/local/opt is not writable.
查找解決方法,如下語句執行成功:
先到local目錄:sudo mkdir opt
再回到~目錄:sudo chown -R `whoami`:admin /usr/local/opt
解決了問題後,從新執行:
brew link mysql
提示:
Linking /usr/local/Cellar/mysql/8.0.11... 79 symlinks created
從新執行:
mysql.server start
登陸mysql:
mysql -uroot
報錯:
dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
Referenced from: /usr/local/bin/mysql
Reason: image not found
或啓動CMS後臺python main.py runwebapp時,報錯:
mportError: dlopen(/Library/Python/2.7/site-packages/_mysql.so, 2): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
Referenced from: /usr/local/opt/mysql/lib/libmysqlclient.20.dylib
Reason: image not found
解決:參考(Mac openssl未找到/加載失敗問題處理 https://www.jianshu.com/p/c6d6a60002e4)
brew remove openssl
brew uninstall --force openssl
brew install openssl
再次登陸:
mysql -uroot
成功!
補充:
問題:Library not loaded libmysqlclient.20.dylib image not found
libmysqlclient.20.dylib brew安裝的最新是 libmysqlclient.21.dylib
解決方法:
到該目錄查看(/usr/local/opt/mysql/lib/):ls -l libmysqlclient.21.dylib
先備份,命令: sudo cp libmysqlclient.21.dylib libmysqlclient.21.dylib.backup
再映射地址,命令:sudo ln -s /usr/local/opt/mysql/lib/libmysqlclient.21.dylib /usr/local/opt/mysql/lib/libmysqlclient.20.dylib
查看映射狀況:ls -l libmysqlclient.21.dylib