V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
wsgzao
V2EX  ›  MySQL

macOS Mojave 降级安装 MySQL 5.7

  •  
  •   wsgzao ·
    wsgzao · 2018-12-18 16:50:53 +08:00 · 4320 次点击
    这是一个创建于 2159 天前的主题,其中的信息可能已经有所发展或是发生改变。

    前言

    自从 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 [email protected]
    brew link --force [email protected]
    
    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
    
    [email protected] 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 [email protected] first in your PATH run:
      echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
    
    For compilers to find [email protected] you may need to set:
      export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
      export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
    
    For pkg-config to find [email protected] you may need to set:
      export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
    
    
    To have launchd start [email protected] now and restart at login:
      brew services start [email protected]
    Or, if you don't want/need a background service you can just run:
      /usr/local/opt/[email protected]/bin/mysql.server start
    
    # 开机自启动
    brew services restart [email protected]
    # 设置环境变量
    echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
    # 手动启动和关闭
    /usr/local/opt/[email protected]/bin/mysql.server start
    /usr/local/opt/[email protected]/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.
    
    
    7 条回复    2018-12-21 22:57:26 +08:00
    good
        1
    good  
       2018-12-18 17:13:19 +08:00
    为啥不用 docker 装?
    wsgzao
        2
    wsgzao  
    OP
       2018-12-18 17:16:42 +08:00
    @good #1 这是一个好主意
    wizardoz
        3
    wizardoz  
       2018-12-18 17:19:40 +08:00
    macOS 的 docker 安装 mysql 5.7 也有 BUG,读写的时候会卡死好长时间。
    good
        4
    good  
       2018-12-18 17:33:34 +08:00
    @wizardoz #3 确实有问题 插大量的数据后 Sequel Pro 就连不上了,重新生成 mysql 容器也不行,只能重启电脑才能连
    Everyxin
        5
    Everyxin  
       2018-12-18 17:34:41 +08:00
    docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=你的密码 -d mysql:5.7
    一行解决
    mingyun
        6
    mingyun  
       2018-12-18 22:39:40 +08:00
    @Everyxin 这么 6
    rim99
        7
    rim99  
       2018-12-21 22:57:26 +08:00 via Android
    我们的项目开发调试的时候就用 docker 跑 MySQL,没见着卡啊
    @wizardoz
    @good
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2829 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 06:53 · PVG 14:53 · LAX 22:53 · JFK 01:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.