1、brew update更新包
2、brew install mysql 安装mysql
先使用 brew search mysql 查看可下载的版本,然后指定版本下载安装mysql
$ brew install mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.21.high_sierra.bottle.tar.gz
Already downloaded: /Users/Jimmy/Library/Caches/Homebrew/mysql-5.7.21.high_sierra.bottle.tar.gz
==> Pouring mysql-5.7.21.high_sierra.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
? /usr/local/Cellar/mysql/5.7.21: 323 files, 233.9MB
3.启动mysql服务