Mac下使用homebrew管理多版本mysql同时

Mac下使用homebrew管理多版本mysql同时启动

思路

给每个版本分配不同的数据目录和配置文件即可

本文尝试了使用 brew 安装管理多个MySQL版本,同时运行、直接切换

安装

如果已有数据文件请自行备份以及使用

安装 mysql 5.7
shell 复制代码
brew install [email protected]

/opt/homebrew/var/mysql 目录为空时,安装过程会自动生成数据目录,可在安装过程中看到执行了生成数据目录的命令 (目录如果有文件则不会执行该命令)

复制代码
/opt/homebrew/Cellar/[email protected]/5.7.41/bin/mysqld --initialize-insecure --user=XXXX --basedir=/opt/homebrew/Cellar/[email protected]/5.7.41 --datadir=/opt/homebrew/var/mysql --tmpdir=/tmp

准备好5.7的文件

shell 复制代码
mv /opt/homebrew/var/mysql  /opt/homebrew/var/[email protected]
cp /opt/homebrew/etc/my.cnf /opt/homebrew/etc/[email protected]

修改配置文件

  • 指定配置文件--defaults-file
  • 修改datadirWorkingDirectory路径
shell 复制代码
...
ExecStart=/opt/homebrew/opt/[email protected]/bin/mysqld_safe --defaults-file=/opt/homebrew/etc/[email protected]  --datadir=/opt/homebrew/var/[email protected]
...
WorkingDirectory=/opt/homebrew/var/[email protected]
...

/opt/homebrew/Cellar/[email protected]/5.7.41/[email protected]
...
<array>
    <string>/opt/homebrew/opt/[email protected]/bin/mysqld_safe</string>
    <string>--defaults-file=/opt/homebrew/etc/[email protected]</string>
    <string>--datadir=/opt/homebrew/var/[email protected]</string>
</array>
...
<key>WorkingDirectory</key>
<string>/opt/homebrew/var/[email protected]</string>
...

/opt/homebrew/Cellar/[email protected]/5.7.41/[email protected]

更改端口和socket不需要同时运行的可以不改

plain 复制代码
[mysqld]
port = 3307
socket = /tmp/[email protected]

/opt/homebrew/etc/[email protected]

启动 & 测试

shell 复制代码
brew services stop [email protected]
brew services start [email protected]
安装 mysql 8.0
plain 复制代码
brew install [email protected]
brew services start mysql

数据目录和配置文件就不改了,使用默认的

结束

多版本完美运行

分别重置密码

复制代码
mysql_secure_installation -h127.0.0.1 -P3307

连接不同服务端

复制代码
mysql -h127.0.0.1 -P3307
相关推荐
betazhou4 分钟前
有没有 MariaDB 5.5.56 对应 MySQL CONNECTION_CONTROL 插件
linux·数据库·mysql·oracle·mariadb
Elohim81510 分钟前
数据库SQLite基础
数据库·sqlite
TDengine (老段)21 分钟前
TDengine 支持的平台汇总
大数据·数据库·物联网·时序数据库·iot·tdengine·涛思数据
异常君22 分钟前
MySQL 中 count(*)、count(1)、count(字段)性能对比:一次彻底搞清楚
java·mysql·面试
烟雨书信37 分钟前
Linux中MySQL的逻辑备份与恢复
linux·运维·mysql
大熊猫侯佩1 小时前
由一个 SwiftData “诡异”运行时崩溃而引发的钩深索隐(四)
数据库·swiftui·apple watch
想用offer打牌1 小时前
面试官问:Redis和MySQL数据一致,为什么还需要MySQL?🤠
数据库·redis·mysql
chen.@-@2 小时前
后端下载限速(redis记录实时并发,bucket4j动态限速)
数据库·redis·缓存
王小小鸭2 小时前
【Oracle APEX开发小技巧12】
数据库·oracle
噼里啪啦啦.2 小时前
Spring事务和事务传播机制
数据库·sql·spring