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
相关推荐
云闲不收1 小时前
mysql如何快速生成测试大数据库
数据库·mysql·oracle
YUJIANYUE1 小时前
PHP7+MySQL5.6 雪里开简易预约制访客管理系统V1.0
mysql·php
LIU_Skill4 小时前
MySQL用户管理与权限控制详解
android·数据库·mysql
dayceng6 小时前
一则复杂 SQL 改写后有感
java·数据库·mysql
LuLaLuLaLeLLLLLL6 小时前
MySQL 基础笔记
数据库·笔记·mysql
掘根6 小时前
【MySQL进阶】MySQL程序
数据库·mysql
neoooo7 小时前
SQL中JOIN操作的条件使用总结与最佳实践
java·后端·mysql
程序员岳焱7 小时前
Linux服务器上MySQL磁盘I/O性能瓶颈诊断与分析
java·linux·mysql
Lx3527 小时前
覆盖索引:减少回表查询的关键技巧
后端·sql·mysql
hqxstudying7 小时前
JAVA面试题
java·jvm·数据库·redis·mysql·oracle