眾所周知,在Mac系統中安裝MySQL相對來說比較簡單,但是有時候我們可能需要安裝兩個不同版本的MySQL,本文將介紹如何在Mac中安裝兩個不同版本的MySQL。
步驟如下:
第一步:下載MySQL以及MySQL源碼
brew install mysql@5.7
brew install mysql@8.0
第二步:啟動MySQL服務并設置自啟
brew services start mysql@5.7
brew services start mysql@8.0
brew services list
sudo mkdir -p /Library/LaunchDaemons
sudo cp /usr/local/opt/mysql@5.7/homebrew.mxcl.mysql@5.7.plist /Library/LaunchDaemons/
sudo cp /usr/local/opt/mysql@8.0/homebrew.mxcl.mysql@8.0.plist /Library/LaunchDaemons/
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.mysql@5.7.plist
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.mysql@8.0.plist
sudo launchctl list | grep mysql
第三步:設置端口號
sudo mkdir -p /etc/my.cnf.d
sudo cp /usr/local/opt/mysql@5.7/my.cnf /etc/my.cnf.d/mysql5.7.cnf
sudo cp /usr/local/opt/mysql@8.0/my.cnf /etc/my.cnf.d/mysql8.0.cnf
sudo vim /etc/my.cnf.d/mysql5.7.cnf
#修改port = 3306為port = 3307
sudo vim /etc/my.cnf.d/mysql8.0.cnf
#修改port = 3306為port = 3308
第四步:啟動MySQL
sudo mysql.server start
sudo mysql.server start --port=3307 --datadir=/usr/local/var/mysql57
sudo mysql.server start --port=3308 --datadir=/usr/local/var/mysql80
現在你已經成功安裝了兩個版本的MySQL,并實現了兩個MySQL服務的自啟動。