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/11/6 21:15:50 阅读更多 →
软件工程毕业设计本科生课题集合

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

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

2026/11/6 21:15:50 阅读更多 →
【从0开发一个 Agent】第三章:初始化项目

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

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

2026/11/6 18:46:12 阅读更多 →

最新新闻

Electron桌面应用开发实战:从环境搭建到打包发布全流程

Electron桌面应用开发实战:从环境搭建到打包发布全流程

做前端这些年,我大部分时间都在跟浏览器标签页打交道,直到第一次把桌面应用跑起来,才发现原来自己一直被限制在地址栏和刷新按钮围起来的框框里。Electron这个词,最开始是在某段时间频繁出现在同事的讨论里,一个用HTML…

2026/11/6 15:21:35 阅读更多 →
滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

简介:亚太天能T109滑盖智能锁产品说明书是一份PDF格式的官方技术文档,主要面向智能锁安装人员、终端用户及售后维护者,帮助快速掌握产品安装、配置与常见故障处理。全包仅1个PDF文件,大小4.37MB,内容结构清晰&#xff…

2026/11/6 9:29:27 阅读更多 →
PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

上个月我在调试一台高速AGV的驱动系统,整车要求空载跑到8m/s,电机转速已经拉到额定点,驱动器的输出电压也顶到了母线电压极限附近。再往上踩速度指令,转速纹丝不动,三相电流反而开始震荡。那会儿我的第一反应就是&…

2026/11/5 12:28:01 阅读更多 →
C++核心知识点:从内存管理到STL的实战指南

C++核心知识点:从内存管理到STL的实战指南

C 这门语言我前前后后折腾了十几年,用它写过嵌入式驱动、做过游戏服务端,也搭过基础组件库。每次看到新人一头扎进"C 核心知识点"这个搜索词,我其实挺感慨的——这门语言的难点从来不是语法多,而是知识点之间的耦合太深…

2026/11/5 12:28:02 阅读更多 →
T109滑盖智能锁怎么装?安装调试与故障排查全攻略

T109滑盖智能锁怎么装?安装调试与故障排查全攻略

简介:亚太天能T109滑盖智能锁产品说明书以PDF格式发布,适合智能锁用户、安装人员与售后维修人员阅读。内容围绕T109系列指纹密码刷卡锁展开,先介绍前面板、后面板、锁体、机械钥匙、电池盒盖等部件名称与功能,再给出完整安装步骤&…

2026/11/6 8:08:42 阅读更多 →
LLM知识降熵:从信息垄断到理解权下放

LLM知识降熵:从信息垄断到理解权下放

你有没有过这种经历:翻开源码注释、论文摘要或者一份专业报告,每个字都认识,连在一起却像天书。想找人聊聊,身边要么没人懂,要么懂的懒得跟你解释。后来我试着把同一段内容丢给一个大语言模型,几秒钟之后&a…

2026/11/5 19:38:59 阅读更多 →

日新闻

周新闻

月新闻