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

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

思路

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

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

安装

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

安装 mysql 5.7
shell 复制代码
brew install mysql@5.7

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

复制代码
/opt/homebrew/Cellar/mysql@5.7/5.7.41/bin/mysqld --initialize-insecure --user=XXXX --basedir=/opt/homebrew/Cellar/mysql@5.7/5.7.41 --datadir=/opt/homebrew/var/mysql --tmpdir=/tmp

准备好5.7的文件

shell 复制代码
mv /opt/homebrew/var/mysql  /opt/homebrew/var/mysql@5.7
cp /opt/homebrew/etc/my.cnf /opt/homebrew/etc/my@5.7.cnf

修改配置文件

  • 指定配置文件--defaults-file
  • 修改datadirWorkingDirectory路径
shell 复制代码
...
ExecStart=/opt/homebrew/opt/mysql@5.7/bin/mysqld_safe --defaults-file=/opt/homebrew/etc/my@5.7.cnf  --datadir=/opt/homebrew/var/mysql@5.7
...
WorkingDirectory=/opt/homebrew/var/mysql@5.7
...

/opt/homebrew/Cellar/mysql@5.7/5.7.41/homebrew.mysql@5.7.service
...
<array>
    <string>/opt/homebrew/opt/mysql@5.7/bin/mysqld_safe</string>
    <string>--defaults-file=/opt/homebrew/etc/my@5.7.cnf</string>
    <string>--datadir=/opt/homebrew/var/mysql@5.7</string>
</array>
...
<key>WorkingDirectory</key>
<string>/opt/homebrew/var/mysql@5.7</string>
...

/opt/homebrew/Cellar/mysql@5.7/5.7.41/homebrew.mxcl.mysql@5.7.plist

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

plain 复制代码
[mysqld]
port = 3307
socket = /tmp/mysql@5.7.sock

/opt/homebrew/etc/my@5.7.cnf

启动 & 测试

shell 复制代码
brew services stop mysql@5.7
brew services start mysql@5.7
安装 mysql 8.0
plain 复制代码
brew install mysql@8.0
brew services start mysql

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

结束

多版本完美运行

分别重置密码

复制代码
mysql_secure_installation -h127.0.0.1 -P3307

连接不同服务端

复制代码
mysql -h127.0.0.1 -P3307
相关推荐
其实防守也摸鱼9 分钟前
免杀与持久化入门:从载荷免杀到隐蔽通道的完整指南
运维·服务器·数据库·安全·github·copilot·渗透
SelectDB9 分钟前
统一全文检索与 SQL 分析:Apache Doris 日志分析实践
运维·数据库·掘金技术征文
麻瓜code19 分钟前
【MySQL】SQL优化实战:从慢查询定位到查询改写
数据库·sql·mysql
蓝鸟19741 小时前
Oracle HIS业务视图优化实战|VI_BQ_YWTX11从高耗费到秒级响应
数据库·oracle·his数据库调优·复合索引踩坑·is null索引问题·ql视图优化
数智启示录1 小时前
Apache Doris 4.0.8 混合检索实战(第 5 篇):三套系统只返回两条结果,一条 SQL 如何避开交集丢失
大数据·数据库·经验分享·sql·面试
今天AI了吗1 小时前
大模型技术全景(一):AI、机器学习、深度学习,三者的关系到底是什么?一文搞懂
数据库·人工智能·python·sql·深度学习·机器学习·rust
这个DBA有点耶1 小时前
RANGE/LIST/HASH/二级分区怎么选?分区表适用边界与隐藏代价
数据库·mysql·dba
离陌在学C#2 小时前
C# 异步编程:从 async/await 到 Task 实战指南
开发语言·数据库·c#
还是大剑师兰特2 小时前
MySQL8.0 Windows完整安装教程
windows·mysql·大剑师
2601_962074682 小时前
Spring Boot的无缝衔接:深入解析与实践
数据库·spring boot·后端