卸载以前的版本
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/mysql
brew services list
brew services stop mysql@5.6
brew remove mysql@5.6
rm -rf /usr/local/var/mysql
安装
brew install mysql@5.7
brew services start mysql@5.7
初始化,记下初始密码
mysqld --initialize --datadir=/data/mysql
修改 plist 中的 datadir
vim ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
重新启动 mysql
brew services restart mysql@5.7
ps aux|grep mysql #查看 datadir 是否已经改变!
修改密码
mysql -uroot -p #输入刚才记下的密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
完工。
来源:oschina
链接:https://my.oschina.net/ooxxx/blog/4336006