一、之前失败情况
官网下载dmg文件安装、源码安装,下过5.6 5.7 8.0 版本,都可以安装成功,但是在电脑设置界面无法启动,每次点启动输入密码后,均闪一下绿色然后变红色,既然不能界面启动,那就使用终端试试,结果就是长时间的不停解决各种问题:不能连接到数据库的服务啦、找不到mysql.sock文件啦、PID错误啊等等等等,看过网上各种方式:kill已有mysql进程、新建/修改my.cnf文件、修改配置路径等等等等,数据库也是不断卸载、安装,均已失败告终。
二、完全卸载mysql
在安装之前,一定要完全卸载mysql,并删除相关的各种文件,依次运行以下语句:(如果不是root用户需要在前面加上sudo,也可使用sudo su -进行root)
mymac:~ root# rm -rf /usr/local/mysql*
mymac:~ root# rm -rf /Library/StartupItems/MySQLCOM
mymac:~ root# rm -rf /Library/PreferencePanes/My*
mymac:~ root# rm -rf ~/Library/PreferencePanes/My*
mymac:~ root# rm -rf /Library/Receipts/mysql*
mymac:~ root# rm -rf /Library/Receipts/MySQL*
mymac:~ root# rm -rf /var/db/receipts/com.mysql.*
三、使用brew安装
安装brew并更新:(可参考官网:https://brew.sh/)
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Andale Mono"; color: #75b900; background-color: #252525 }
span.s1 { }
mymac:~ root# /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Andale Mono"; color: #75b900; background-color: #252525 }
span.s1 { }
mymac:~ root# brew update
安装mysql:
不能使用root用户安装,会报错:
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Andale Mono"; color: #75b900; background-color: #252525 }
span.s1 { }
span.s2 { text-decoration: underline; color: #dc4f33 }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Andale Mono"; color: #75b900; background-color: #252525 }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Andale Mono"; color: #ff871a; background-color: #252525 }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Andale Mono"; color: #75b900; background-color: #252525; min-height: 16.0px }
span.s1 { }
span.s2 { color: #7248fe }
span.s3 { color: #75b900 }
mymac:~ mymac$ brew install mysql
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.22.el_capitan.bot
Already downloaded: /Users/mymac/Library/Caches/Homebrew/mysql-5.7.22.el_capitan.bottle.tar.gz
==> Pouring mysql-5.7.22.el_capitan.bottle.tar.gz
==> 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
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
==> Summary