Mysql半同步配置
发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,Mysql半同步的原理是主库只需要确认从库接收到了事物即可,无需等待从库应用,相比异步复制,半同步提高了数据完整性的保障,但会增加主库的响应时间。1、安装Mysql并配置主从参考http://blog
千家信息网最后更新 2026年11月02日Mysql半同步配置Mysql半同步的原理是主库只需要确认从库接收到了事物即可,无需等待从库应用,相比异步复制,半同步提高了数据完整性的保障,但会增加主库的响应时间。
1、安装Mysql并配置主从
参考http://blog.itpub.net/28536251/viewspace-2138854/分别在两节点安装Mysql。
参考http://blog.itpub.net/28536251/viewspace-2138928/或者http://blog.itpub.net/28536251/viewspace-2139007/配置主从。
2、在master节点加载半同步插件
(root@localhost)[(none)] install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.16 sec)
3、在slave节点加载半同步插件
(root@localhost)[(none)] install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.45 sec)
4、在master节点设置以下变量
(root@localhost)[(none)] set global rpl_semi_sync_master_enabled=1;
Query OK, 0 rows affected (0.05 sec)
#rpl_semi_sync_master_enabled用于控制是否在master节点启用半同步复制,为1表示启动。
(root@localhost)[(none)] set global rpl_semi_sync_master_timeout=3000;
Query OK, 0 rows affected (0.00 sec)
#rpl_semi_sync_master_timeout用于指定master节点等待slave响应的事件,单位是毫秒,默认是10000即10秒钟,这里设置为3秒。若超出指定时间slave节点仍无响应,那么当前复制环境就临时被转换为异步复制。
5、在slave节点设置以下变量
(root@localhost)[(none)] set global rpl_semi_sync_slave_enabled=1;
Query OK, 0 rows affected (0.09 sec)
#rpl_semi_sync_slave_enabled用来控制slave节点是否启用半同步复制。
以上3个变量虽然可以动态修改,但强烈建议将所有配置的变量都保存在初始化参数文件中,这样在每次启动mysql服务时就无需再手动配置了。
6、在slave节点重启io_thread线程
slave节点重新连接master节点,注册为半同步身份。
(root@localhost)[(none)] stop slave io_thread;
Query OK, 0 rows affected (0.12 sec)
(root@localhost)[(none)] start slave io_thread;
Query OK, 0 rows affected (0.02 sec)
7、测试
主库插入数据:
(root@localhost)[(none)] use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
(root@localhost)[test] show tables;
+----------------+
| Tables_in_test |
+----------------+
| tb1 |
+----------------+
1 row in set (0.00 sec)
(root@localhost)[test] select * from tb1;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.03 sec)
(root@localhost)[test] insert into tb1 values(2);
Query OK, 1 row affected (0.10 sec)
(root@localhost)[test] select * from tb1;
+------+
| id |
+------+
| 1 |
| 2 |
+------+
2 rows in set (0.02 sec)
(root@localhost)[test] show status like 'rpl_semi_sync%';
+--------------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients | 1 |
| Rpl_semi_sync_master_net_avg_wait_time | 0 |
| Rpl_semi_sync_master_net_wait_time | 0 |
| Rpl_semi_sync_master_net_waits | 1 |
| Rpl_semi_sync_master_no_times | 0 |
| Rpl_semi_sync_master_no_tx | 0 |
| Rpl_semi_sync_master_status | ON |
| Rpl_semi_sync_master_timefunc_failures | 0 |
| Rpl_semi_sync_master_tx_avg_wait_time | 52899 |
| Rpl_semi_sync_master_tx_wait_time | 52899 |
| Rpl_semi_sync_master_tx_waits | 1 |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
| Rpl_semi_sync_master_wait_sessions | 0 |
| Rpl_semi_sync_master_yes_tx | 1 |
+--------------------------------------------+-------+
14 rows in set (0.05 sec)
其中:
rpl_semi_sync_master_clients为1表示处于半同步模式的slave节点有1个。
rpl_semi_sync_master_status为ON表示master节点启用了半同步模式。
rpl_semi_sync_master_no_tx为0表示还没有未成功发送到slave节点的事物数量。
rpl_semi_sync_master_yes_tx为1表示已成功发送到slave节点的事物数量为1。
备库查看:
(root@localhost)[test] select * from tb1;
+------+
| id |
+------+
| 1 |
| 2 |
+------+
2 rows in set (0.00 sec)
1、安装Mysql并配置主从
参考http://blog.itpub.net/28536251/viewspace-2138854/分别在两节点安装Mysql。
参考http://blog.itpub.net/28536251/viewspace-2138928/或者http://blog.itpub.net/28536251/viewspace-2139007/配置主从。
2、在master节点加载半同步插件
(root@localhost)[(none)] install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.16 sec)
3、在slave节点加载半同步插件
(root@localhost)[(none)] install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.45 sec)
4、在master节点设置以下变量
(root@localhost)[(none)] set global rpl_semi_sync_master_enabled=1;
Query OK, 0 rows affected (0.05 sec)
#rpl_semi_sync_master_enabled用于控制是否在master节点启用半同步复制,为1表示启动。
(root@localhost)[(none)] set global rpl_semi_sync_master_timeout=3000;
Query OK, 0 rows affected (0.00 sec)
#rpl_semi_sync_master_timeout用于指定master节点等待slave响应的事件,单位是毫秒,默认是10000即10秒钟,这里设置为3秒。若超出指定时间slave节点仍无响应,那么当前复制环境就临时被转换为异步复制。
5、在slave节点设置以下变量
(root@localhost)[(none)] set global rpl_semi_sync_slave_enabled=1;
Query OK, 0 rows affected (0.09 sec)
#rpl_semi_sync_slave_enabled用来控制slave节点是否启用半同步复制。
以上3个变量虽然可以动态修改,但强烈建议将所有配置的变量都保存在初始化参数文件中,这样在每次启动mysql服务时就无需再手动配置了。
6、在slave节点重启io_thread线程
slave节点重新连接master节点,注册为半同步身份。
(root@localhost)[(none)] stop slave io_thread;
Query OK, 0 rows affected (0.12 sec)
(root@localhost)[(none)] start slave io_thread;
Query OK, 0 rows affected (0.02 sec)
7、测试
主库插入数据:
(root@localhost)[(none)] use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
(root@localhost)[test] show tables;
+----------------+
| Tables_in_test |
+----------------+
| tb1 |
+----------------+
1 row in set (0.00 sec)
(root@localhost)[test] select * from tb1;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.03 sec)
(root@localhost)[test] insert into tb1 values(2);
Query OK, 1 row affected (0.10 sec)
(root@localhost)[test] select * from tb1;
+------+
| id |
+------+
| 1 |
| 2 |
+------+
2 rows in set (0.02 sec)
(root@localhost)[test] show status like 'rpl_semi_sync%';
+--------------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients | 1 |
| Rpl_semi_sync_master_net_avg_wait_time | 0 |
| Rpl_semi_sync_master_net_wait_time | 0 |
| Rpl_semi_sync_master_net_waits | 1 |
| Rpl_semi_sync_master_no_times | 0 |
| Rpl_semi_sync_master_no_tx | 0 |
| Rpl_semi_sync_master_status | ON |
| Rpl_semi_sync_master_timefunc_failures | 0 |
| Rpl_semi_sync_master_tx_avg_wait_time | 52899 |
| Rpl_semi_sync_master_tx_wait_time | 52899 |
| Rpl_semi_sync_master_tx_waits | 1 |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
| Rpl_semi_sync_master_wait_sessions | 0 |
| Rpl_semi_sync_master_yes_tx | 1 |
+--------------------------------------------+-------+
14 rows in set (0.05 sec)
其中:
rpl_semi_sync_master_clients为1表示处于半同步模式的slave节点有1个。
rpl_semi_sync_master_status为ON表示master节点启用了半同步模式。
rpl_semi_sync_master_no_tx为0表示还没有未成功发送到slave节点的事物数量。
rpl_semi_sync_master_yes_tx为1表示已成功发送到slave节点的事物数量为1。
备库查看:
(root@localhost)[test] select * from tb1;
+------+
| id |
+------+
| 1 |
| 2 |
+------+
2 rows in set (0.00 sec)
节点
同步
配置
变量
成功
主从
事物
插件
数据
数量
时间
模式
参考
控制
事件
动态
单位
原理
参数
完整性
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
云南咖啡
中资互联网科技
易互联网科技有限公司
互联网 科技创业
奇酷互联网络科技公司
深圳期待互联网科技
互联网科技博客
互联网科技宣传片
无锡溥仪互联网科技有限公司
银川新华互联网科技学校地址
安控科技rtu产品工业互联网
北京华百购互联网科技有限公司
互联网软件和科技
哈尔滨屹滨互联网科技有限公司
河南住房之家互联网科技
风投北京互联网科技
科技互联网公司两年变化
北京瑞云互联网科技有限公司
互联网高科技绘画
武汉亿视互联网科技有限公司
科技互联网企业
高科技互联网
互联网科技媒体
互联网科技论文
汇久创客互联网科技
互联网女皇 腾讯科技
上海宁丞科技互联网
互联网科技手抄报图片
数字互联网科技有限公司
武汉亿视互联网科技有限公司