安装
# 查询mysql 版本
➜ ~ brew search mysql
==> Formulae
automysqlbackup mysql-client@5.7 mysql@5.6
mysql mysql-connector-c++ mysql@5.7
mysql++ mysql-sandbox mysqltuner
mysql-client mysql-search-replace qt-mysql
==> Casks
mysql-connector-python mysql-utilities navicat-for-mysql
mysql-shell mysqlworkbench sqlpro-for-mysql
# 安装指定版本
brew install mysql@5.7
# 安装成功后的界面信息
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
mysql@5.7 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 mysql@5.7 first in your PATH, run:
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
For compilers to find mysql@5.7 you may need to set:
export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib"
export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include"
To start mysql@5.7:
brew services start mysql@5.7
Or, if you don't want/need a background service you can just run:
/usr/local/opt/mysql@5.7/bin/mysqld_safe --datadir=/usr/local/var/mysql
==> Summary
-- 启动
brew services start mysql@5.7
-- 登录
mysql -uroot -p
# 后台启动
brew services start mysql
# 启动
mysql.server start
# 连接本机 localhost:3306 服务
mysql -uroot -p
# 连接指定host 的mysql服务
mysql -h 192.21.12.42 -P 3306 -u root -p
# 停止
mysql.server stop
# 重启
mysql.server restart
参考:https://www.jianshu.com/p/11ce77ceab3d
https://newsn.net/say/brew-install-mysql57.html