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
相关推荐
rylshe13142 分钟前
在scala中sparkSQL连接mysql并添加新数据
开发语言·mysql·scala
fmdpenny7 分钟前
SQL中联表的运用
数据库·sql
不剪发的Tony老师14 分钟前
互联网SQL面试题:用户会话时长分析
数据库·sql
睡觉z32 分钟前
Shell编程之正则表达式与文本处理器
数据库·mysql·正则表达式
TDengine (老段)35 分钟前
TDengine 做为 Spark 数据源
大数据·数据库·物联网·ajax·spark·时序数据库·tdengine
Dreams_l1 小时前
MySQL初阶:查询进阶
数据库·mysql
码农黛兮_461 小时前
数据库数据清洗、预处理与质量监控、 数据质量的核心概念
数据库
张哈大3 小时前
【 Redis | 实战篇 秒杀实现 】
数据库·redis·缓存
weixin_472339463 小时前
Postgresql与openguass对比
数据库·postgresql
程序员曼布4 小时前
主从架构:技术原理与实现
redis·mysql·架构