1.清除之前安裝的MySQL
先停止所有mysql有關程序
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*
如果
brew
之前安裝過也要解除安裝
2. 安裝MySQL
執行
brew install [email protected]
,
然後出現
➜ ~ brew install [email protected]
==> Downloading https://homebrew.bintray.com/bottles/[email protected]
Already downloaded: /Users/duheyuan/Library/Caches/Homebrew/downloads/9d9f1018[email protected]5.7-5.7.29.catalina.bottle.tar.gz
==> Pouring [email protected]
==> /usr/local/Cellar/[email protected]/5.7.29/bin/mysqld --initialize-insecure --user=duheyuan --basedir=/u
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
[email protected] is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have [email protected] first in your PATH run:
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
For compilers to find [email protected] you may need to set:
export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
For pkg-config to find [email protected] you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
To have launchd start [email protected] now and restart at login:
brew services start [email protected]
Or, if you don't want/need a background service you can just run:
/usr/local/opt/[email protected]/bin/mysql.server start
==> Summary
🍺 /usr/local/Cellar/[email protected]/5.7.29: 319 files, 232.3MB
安裝完成,接下來我們要根據提示運作
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
, 把
MySQL
路徑寫到
zshrc
裡,沒裝
zsh
的寫入到
bash_profile
.
然後來一個靈魂一擊,
source ~/.zshrc
or
source ~/.bash_profile
啟動MySQL
brew services start [email protected]
or
/usr/local/opt/[email protected]/bin/mysql.server start
.
要想直接使用
mysql.server start
需要配置
zshrc
檔案.
vim ~/.zshrc
打開後添加
alias mysql="/usr/local/opt/[email protected]/bin/mysql"
然後再來一遍
source ~/.zshrc
搞定
最後記一下安裝過程中出現的問題
在啟動時候出現了一個錯誤
ERROR! The server quit without updating PID file (/usr/local/var/mysql/MacBook-Pro.local.pid).
找了很多文章嘗試發現都不行,因為裡面是本地的資料庫檔案,平時開發用的線上資料庫是以幹脆放棄删除掉了,然後重新安裝資料庫,okay了