请注意,本文编写于 2126 天前,最后修改于 1140 天前,其中某些信息可能已经过时。
- 查看是否有mysql57安装包
$ brew search mysql
==> Formulae
automysqlbackup mysql++ mysql-cluster mysql-connector-c++ mysql-search-replace mysql@5.5 mysql@5.7
mysql mysql-client mysql-connector-c mysql-sandbox mysql-utilities mysql@5.6 mysqltuner
==> Casks
mysql-connector-python mysql-shell mysql-utilities mysqlworkbench navicat-for-mysql sqlpro-for-mysql
- 安装mysql57
$ brew install mysql@5.7
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask-fonts).
No changes to formulae.
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/mysql@5.7-5.7.25.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mysql@5.7-5.7.25.mojave.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
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"
For pkg-config to find mysql@5.7 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/mysql@5.7/lib/pkgconfig"
To have launchd start mysql@5.7 now and restart at login:
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/mysql.server start
==> Summary
/usr/local/Cellar/mysql@5.7/5.7.25: 319 files, 234MB
- 安装后按照上面命令添加全局变量
- 但是mysql还是死活都启动不起来
$ mysql.server restart
ERROR! MySQL server PID file could not be found!
Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/var/mysql_bak/K-MacBook-Pro.local.pid).
- 只能将原来的目录进行备份,删除 /usr/local/var/mysql 目录,执行 mysqld --initialize 重新初始化一个mysql目录,启动成功
- 但是之前的数据库数据就都没了,后面尝试将新初始化目录中的pid文件复制到旧的备份mysql文件中去,并且设置下 my.conf 文件中的 datadir 的指向配置
1 # Default Homebrew MySQL server config
2 [mysqld]
3 # Only allow connections from localhost
4 bind-address = 127.0.0.1
5
6 datadir = /usr/local/var/mysql/
重新启动成功,并且数据库都回来了