热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

macOSMojave降级安装MySQL5.7

自从macOS升级至Mojave后小问题不断,现在使用Homebrew安装MySQL默认也是8.0版

自从 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/3proxy/

扩展阅读

Install MySQL 5.7 on macOS Mojave - https://medium.com/@at0dd/install-mysql-5-7-on-mac-os-mojave-cd07ec936034

正常安装

默认新版本是 MySQL 8.0

brew update
brew install mysql

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

卸载现有版本

无论是官方 dmg 还是 brew 都记得先备份重要数据后再清理

# 正常关闭并删除 MySQL
mysql.server stop
brew services stop mysql
brew remove mysql

# 无法正常删除 MySQL
ps -ax | grep mysql
stop and kill any MySQL processes
brew remove mysql
brew cleanup
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/mysql*

安装 MySQL 指定版本

# 安装 MySQL 5.7
brew install mysql@5.7
brew link --force mysql@5.7

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

# 开机自启动 
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

安装 mysqldb

Python 中最连接 Mysql 常用的驱动是:

  • mysql-python :mysql 的 C 语言的驱动
  • mysql-connector:msql 官方的驱动
  • pymysql:python 语言的驱动
# 使用 MySQLdb ,但是提示 importerror no module named mysqldb
brew install mysql-connector-c
pip install mysql-python

# 可能会出现以下错误,按照提示做即可 
Error: Cannot install mysql because conflicting formulae are installed.
  mysql-connector-c: because both install MySQL client libraries

Please `brew unlink mysql-connector-c` before continuing.

Unlinking removes a formula's symlinks from /usr/local. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side-effects in the
resulting software.

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 我们


推荐阅读
author-avatar
手机用户2502884755
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有