前言自从macOS升级至Mojave后小问题不断,现在使用Homebrew安装MySQL默认也是8.0版本,和Python类似我们依赖的组件可能还不支持高版本,新版本的某些更新和调整导致比如Sequel Pro和mysqldb不可用。当然我们也可以使用官方的MySQLWorkbench,之前介绍了如何在macOS下安装多版本Python,现在继续分享macOS如何降级MySQL。macOS Mojave 降级安装 MySQL 5.7更新历史2018年12月17日 - 初稿阅读原文 - https://wsgzao.github.io/post…扩展阅读Install MySQL 5.7 on macOS Mojave - https://medium.com/@at0dd/ins…正常安装默认新版本是MySQL 8.0brew updatebrew install mysqlWe’ve installed your MySQL database without a root password. To secure it run: mysql_secure_installationMySQL is configured to only allow connections from localhost by defaultTo connect run: mysql -urootTo have launchd start mysql now and restart at login: brew services start mysqlOr, if you don’t want/need a background service you can just run: mysql.server start卸载现有版本无论是官方dmg还是brew都记得先备份重要数据后再清理# 正常关闭并删除MySQLmysql.server stopbrew services stop mysqlbrew remove mysql# 无法正常删除MySQLps -ax | grep mysqlstop and kill any MySQL processesbrew remove mysqlbrew cleanupsudo rm /usr/local/mysqlsudo rm -rf /usr/local/var/mysqlsudo rm -rf /usr/local/mysql*安装MySQL指定版本# 安装MySQL 5.7brew install mysql@5.7brew link –force mysql@5.7We’ve installed your MySQL database without a root password. To secure it run: mysql_secure_installationMySQL is configured to only allow connections from localhost by defaultTo connect run: mysql -urootmysql@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"’ >> ~/.zshrcFor 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.7Or, if you don’t want/need a background service you can just run: /usr/local/opt/mysql@5.7/bin/mysql.server start# 开机自启动brew services restart mysql@5.7# 设置环境变量echo ’export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"’ >> ~/.zshrc# 手动启动和关闭/usr/local/opt/mysql@5.7/bin/mysql.server start/usr/local/opt/mysql@5.7/bin/mysql.server stop安装mysqldbPython中最连接Mysql常用的驱动是:mysql-python :mysql的C语言的驱动mysql-connector:msql官方的驱动pymysql:python语言的驱动# 使用MySQLdb ,但是提示importerror no module named mysqldbbrew install mysql-connector-cpip install mysql-python# 可能会出现以下错误,按照提示做即可Error: Cannot install mysql because conflicting formulae are installed. mysql-connector-c: because both install MySQL client librariesPlease brew unlink mysql-connector-c
before continuing.Unlinking removes a formula’s symlinks from /usr/local. You canlink the formula again after the install finishes. You can –force thisinstall, but the build may fail or cause obscure side-effects in theresulting software.