mysql router学习-1 (简单的配置方式)
-- 参考文档https://docs.oracle.com/cd/E17952_01/mysql-shell-8.4-en/admin-api-deploy-router.htmlhttps://dev.mysql.com/doc/mysql-router/8.0/en/mysql-router-deploying-basic-routing.html-- info mysql版本8.4 三个节点的mgr 单主模式。mysql router在192.168.2.100上192.168.2.11 mgr01192.168.2.12 mgr02192.168.2.13 mgr03192.168.2.100 19ctest-- install这里安装了mysql router是8.居然用这种配置模式可以管理mysql8.4 。按照官网的意思mysql版本不能高于mysql router的版本[root19ctest mysql]# yum install mysql-router-community-8.0.46-1.el8.x86_64.rpm-- 把mgr启动起来mysql SELECT * FROM performance_schema.replication_group_members; ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | group_replication_applier | 47b589a3-b3c3-11ef-ba63-000c297e6af7 | mgr02 | 3306 | ONLINE | SECONDARY | 8.4.3 | XCom | | group_replication_applier | 7bf19e8c-b3d1-11ef-b688-000c29e5c624 | mgr03 | 3306 | ONLINE | SECONDARY | 8.4.3 | XCom | | group_replication_applier | e558e52f-b327-11ef-8266-000c291c3ef6 | mgr01 | 3306 | ONLINE | PRIMARY | 8.4.3 | XCom | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ 3 rows in set (0.00 sec) mysql-- mysqlrouter.conf配置文件这里采用比较简单的配置直接写死了[routing:primary] bind_address 0.0.0.0 bind_port 8001 destinations 192.168.2.11:3306,192.168.2.12:3306,192.168.2.13:3306 routing_strategy first-available [routing:secondary] bind_address 0.0.0.0 bind_port 8002 destinations 192.168.2.12:3306 ,192.168.2.13:3306 routing_strategy round-robin--启动mysqlrouter --config/etc/mysqlrouter/mysqlrouter.conf --查看端口[root19ctest mysqlrouter]# netstat -ntlp |grep mysqlrouter tcp 0 0 0.0.0.0:8001 0.0.0.0:* LISTEN 7118/mysqlrouter tcp 0 0 0.0.0.0:8002 0.0.0.0:* LISTEN 7118/mysqlrouter [root19ctest mysqlrouter]#--创建一个用户用来测试连接mysql routercreate user route_user% identified by mysql;--登录到8002端口 mysql route配置中8002是primaryprimary应对的hostname是mgr02 、mgr03./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname [rootmgr01 bin]# [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr03 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr03 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr03 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]#--登录到8001端口 mysql route配置中8001是primaryprimary应对的hostname是mgr01./mysql -uroute_user -h192.168.2.100 -pmysql -P8001 -e select hostname [rootmgr01 bin]# [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8001 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr01 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8001 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr01 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8001 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr01 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8001 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr01 | ------------ [rootmgr01 bin]#-- 关闭掉节点1进行测试这个时候节点2提升为primarymysql select hostname; ------------ | hostname | ------------ | mgr01 | ------------ 1 row in set (0.00 sec) mysql shutdown; Query OK, 0 rows affected (0.00 sec) mysql mysql SELECT * FROM performance_schema.replication_group_members; ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | group_replication_applier | 47b589a3-b3c3-11ef-ba63-000c297e6af7 | mgr02 | 3306 | ONLINE | PRIMARY | 8.4.3 | XCom | | group_replication_applier | 7bf19e8c-b3d1-11ef-b688-000c29e5c624 | mgr03 | 3306 | ONLINE | SECONDARY | 8.4.3 | XCom | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ 2 rows in set (0.01 sec) mysql-- 连接到8001端口 发现连接到的是节点2 mgr02也就是新的primary[rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8001 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8001 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8001 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8001 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]#-- 连接到8002发现连接到的是节点2和节点3mgr02mgr03 。即在节点2和节点3之间轮询[rootmgr01 bin]# [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr03 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr03 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]#-- 把节点1启动加入到mgr中mysql SELECT * FROM performance_schema.replication_group_members; ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | group_replication_applier | 47b589a3-b3c3-11ef-ba63-000c297e6af7 | mgr02 | 3306 | ONLINE | PRIMARY | 8.4.3 | XCom | | group_replication_applier | 7bf19e8c-b3d1-11ef-b688-000c29e5c624 | mgr03 | 3306 | ONLINE | SECONDARY | 8.4.3 | XCom | | group_replication_applier | e558e52f-b327-11ef-8266-000c291c3ef6 | mgr01 | 3306 | ONLINE | SECONDARY | 8.4.3 | XCom | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ 3 rows in set (0.00 sec) mysql-- 连接到8001 是节点2 也就是primary节点[rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8001 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8001 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8001 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]#--连接到8002 是节点2和节点3 即mgr02mgr03. 看起来是根据配置文件中的配置进行轮询的[rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr03 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr03 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr03 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr03 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr03 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr03 | ------------ [rootmgr01 bin]# ./mysql -uroute_user -h192.168.2.100 -pmysql -P8002 -e select hostname mysql: [Warning] Using a password on the command line interface can be insecure. ------------ | hostname | ------------ | mgr02 | ------------ [rootmgr01 bin]#-- 把节点1提升为primary 任意节点执行SELECT group_replication_set_as_primary(e558e52f-b327-11ef-8266-000c291c3ef6); mysql select hostname; ------------ | hostname | ------------ | mgr03 | ------------ 1 row in set (0.00 sec) mysql SELECT group_replication_set_as_primary(e558e52f-b327-11ef-8266-000c291c3ef6); -------------------------------------------------------------------------- | group_replication_set_as_primary(e558e52f-b327-11ef-8266-000c291c3ef6) | -------------------------------------------------------------------------- | Primary server switched to: e558e52f-b327-11ef-8266-000c291c3ef6 | -------------------------------------------------------------------------- 1 row in set (0.01 sec) mysql mysql SELECT * FROM performance_schema.replication_group_members; ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | group_replication_applier | 47b589a3-b3c3-11ef-ba63-000c297e6af7 | mgr02 | 3306 | ONLINE | SECONDARY | 8.4.3 | XCom | | group_replication_applier | 7bf19e8c-b3d1-11ef-b688-000c29e5c624 | mgr03 | 3306 | ONLINE | SECONDARY | 8.4.3 | XCom | | group_replication_applier | e558e52f-b327-11ef-8266-000c291c3ef6 | mgr01 | 3306 | ONLINE | PRIMARY | 8.4.3 | XCom | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ 3 rows in set (0.00 sec) mysql结论这种配置方式在conf配置文件中写死了primary和secondary当实际的primary和secondary有变化的时候不够灵活可能和实际想象的效果不一样不建议生产用测试可以。END

相关新闻

3分钟掌握专业歌词制作:LRC Maker终极免费工具指南

3分钟掌握专业歌词制作:LRC Maker终极免费工具指南

3分钟掌握专业歌词制作:LRC Maker终极免费工具指南 【免费下载链接】lrc-maker 歌词滚动姬|可能是你所能见到的最好用的歌词制作工具 项目地址: https://gitcode.com/gh_mirrors/lr/lrc-maker 还在为喜欢的歌曲找不到精准同步的歌词而烦恼吗&…

2026/7/18 13:53:06阅读更多 →
软件工程毕业设计本科生课题集合

软件工程毕业设计本科生课题集合

文章目录🚩 1 前言1.1 选题注意事项1.1.1 难度怎么把控?1.1.2 题目名称怎么取?1.2 选题推荐1.2.1 起因1.2.2 核心- 如何避坑(重中之重)1.2.3 怎么办呢?🚩2 选题概览🚩 3 项目概览题目1 : 图像隐写算法研究与…

2026/7/18 13:53:06阅读更多 →
【从0开发一个 Agent】第三章:初始化项目

【从0开发一个 Agent】第三章:初始化项目

在上一章中,我们完成了技术选型与架构设计。从本章开始,我们将正式进入工程落地阶段。 万丈高楼平地起,一个优秀的企业级项目,往往取决于最初的项目骨架是否扎实。本章的目标是搭建整个项目的核心骨架,配置好所有核心依…

2026/7/18 13:53:06阅读更多 →
系统规划与管理师-IT 服务团队岗位设计方法论与实践

系统规划与管理师-IT 服务团队岗位设计方法论与实践

一、引言(一)核心概念定义岗位设计是在工作分析输出的岗位说明书基础上,对岗位的工作内容、职责权限、协作关系进行系统性重构的管理活动,核心目标是实现组织绩效提升与员工个人需求满足的双赢,属于软考高级系统规划与…

2026/7/18 14:38:09阅读更多 →
系统规划与管理师-工作分析 — 人力资源管理的核心基础

系统规划与管理师-工作分析 — 人力资源管理的核心基础

一、引言核心概念定义工作分析又称职务分析、岗位分析,是通过系统的方法收集、整理、分析组织中岗位的工作内容、职责权限、工作关系、工作环境,以及任职者所需的知识、技能、能力、素质等要求的系统性活动,本质是对组织分工边界与分工标准的…

2026/7/18 14:38:09阅读更多 →
如何永久保存微信聊天记录:打造个人专属AI记忆库的完整指南

如何永久保存微信聊天记录:打造个人专属AI记忆库的完整指南

如何永久保存微信聊天记录:打造个人专属AI记忆库的完整指南 【免费下载链接】WeChatMsg 提取微信聊天记录,将其导出成HTML、Word、CSV文档永久保存,对聊天记录进行分析生成年度聊天报告 项目地址: https://gitcode.com/GitHub_Trending/we/…

2026/7/18 14:38:09阅读更多 →
Windows11 OpenClaw 2.7.9 本地 AI 智能体完整部署实操手册

Windows11 OpenClaw 2.7.9 本地 AI 智能体完整部署实操手册

✨OpenClaw 全平台资源获取与完整安装流程 适配设备:Windows10/11 64 位、Mac 全机型 部署压缩包体积:45.7MB 运行特点:纯图形可视化操作、无代码操作门槛、本地数据存储 📖开篇简述 OpenClaw(圈内昵称"小龙虾&q…

2026/7/18 14:38:09阅读更多 →
7步掌握USBCopyer:Windows平台USB自动备份工具的完整使用指南

7步掌握USBCopyer:Windows平台USB自动备份工具的完整使用指南

7步掌握USBCopyer:Windows平台USB自动备份工具的完整使用指南 【免费下载链接】USBCopyer 😉 用于在插上U盘后自动按需复制该U盘的文件。”备份&偷U盘文件的神器”(写作USBCopyer,读作USBCopier) 项目地址: http…

2026/7/18 14:38:09阅读更多 →
3分钟掌握星露谷物语XNB解包神器:StardewXnbHack完全指南

3分钟掌握星露谷物语XNB解包神器:StardewXnbHack完全指南

3分钟掌握星露谷物语XNB解包神器:StardewXnbHack完全指南 【免费下载链接】StardewXnbHack A simple one-way XNB unpacker for Stardew Valley. 项目地址: https://gitcode.com/gh_mirrors/st/StardewXnbHack 你是否曾经想要修改星露谷物语中的游戏资源&…

2026/7/18 14:33:09阅读更多 →
VSCode TypeScript 环境配置对比:全局安装 vs 项目本地安装的4个关键差异

VSCode TypeScript 环境配置对比:全局安装 vs 项目本地安装的4个关键差异

VSCode TypeScript 环境配置对比:全局安装 vs 项目本地安装的4个关键差异当你在VSCode中启动一个新的TypeScript项目时,第一个技术决策往往从安装方式开始。这个看似简单的选择——全局安装还是项目本地安装——实际上会深刻影响你的开发流程、团队协作和…

2026/7/18 10:49:13阅读更多 →
智慧树刷课插件:5分钟实现自动化学习的智能助手

智慧树刷课插件:5分钟实现自动化学习的智能助手

智慧树刷课插件:5分钟实现自动化学习的智能助手 【免费下载链接】zhihuishu 智慧树刷课插件,自动播放下一集、1.5倍速度、无声 项目地址: https://gitcode.com/gh_mirrors/zh/zhihuishu 智慧树刷课插件是一款专为智慧树在线教育平台设计的Chrome浏…

2026/7/18 8:49:08阅读更多 →
Steam创意工坊下载器WorkshopDL:跨平台游戏模组获取的终极解决方案

Steam创意工坊下载器WorkshopDL:跨平台游戏模组获取的终极解决方案

Steam创意工坊下载器WorkshopDL:跨平台游戏模组获取的终极解决方案 【免费下载链接】WorkshopDL WorkshopDL - The Best Steam Workshop Downloader 项目地址: https://gitcode.com/gh_mirrors/wo/WorkshopDL 你是否在GOG或Epic Games Store购买了心仪的游戏…

2026/7/17 13:22:23阅读更多 →
从模糊意图到可执行指令:Claude PRD中Prompt Engineering与需求颗粒度的5级映射法则

从模糊意图到可执行指令:Claude PRD中Prompt Engineering与需求颗粒度的5级映射法则

更多请点击: https://kaifayun.com 第一章:从模糊意图到可执行指令:Claude PRD中Prompt Engineering与需求颗粒度的5级映射法则 在Claude驱动的产品需求文档(PRD)生成实践中,原始业务意图往往以自然语言片…

2026/7/18 0:00:14阅读更多 →
Cursor配置生成失效?3大隐藏陷阱+4行修复代码,资深工程师连夜整理的紧急补救清单

Cursor配置生成失效?3大隐藏陷阱+4行修复代码,资深工程师连夜整理的紧急补救清单

更多请点击: https://codechina.net 第一章:Cursor配置生成失效?3大隐藏陷阱4行修复代码,资深工程师连夜整理的紧急补救清单 Cursor 配置生成突然失效,是近期高频报障场景。表面看是 cursor.config.json 未更新或 LSP…

2026/7/18 0:00:14阅读更多 →
某智驾大牛创业

某智驾大牛创业

作者:钟声编辑:Mark出品:红色星际头图:智能驾驶图片据悉,国内某头部智驾公司端到端模型技术大牛Z投身创业,并且已经拿到融资。Z不仅是该头部公司内部最年轻的对标阿里P10级别技术负责⼈,更是业内…

2026/7/18 0:00:14阅读更多 →
YOLOv8推理性能优化:从1.2FPS到35FPS的全链路加速实践

YOLOv8推理性能优化:从1.2FPS到35FPS的全链路加速实践

如果你在部署 YOLOv8 时,发现推理速度只有可怜的 1-2 FPS,而别人的演示视频却能跑到 30 FPS 以上,那么问题很可能不在模型本身,而在于你的整个处理链路。很多开发者拿到一个训练好的 YOLOv8 模型后,会直接使用官方示例…

2026/7/17 22:48:46阅读更多 →
Coze与Dify对比指南:低代码AI应用开发从入门到实战

Coze与Dify对比指南:低代码AI应用开发从入门到实战

1. 从零到一:为什么你需要了解 Coze 和 Dify?如果你对 AI 应用开发感兴趣,但一看到“大模型”、“智能体”、“工作流”这些词就头疼,觉得门槛太高,那这篇文章就是为你准备的。很多开发者,包括我自己&#…

2026/7/17 13:22:38阅读更多 →
AI生图工具怎么选?2026年6月版实测对比

AI生图工具怎么选?2026年6月版实测对比

做自媒体的朋友应该都有体会:配图一直是个让人头疼的问题。2026年,AI生图工具已经非常成熟了,但工具太多反而不知道怎么选。以下是截至2026年6月我对主流AI生图工具的实测对比。Midjourney V8.1:速度之王2026年6月11日&#xff0c…

2026/7/17 17:26:50阅读更多 →