MySQL 5.6 支持延迟复制,可以在Slave服务器指定一个延迟的值。默认值为0秒。使用MASTER_DELAY 选项为CHANGE MASTERTO 设置N秒延迟。
1. 下面来实际演示,正常运行的从节点执行,设置延迟100秒
STOP SLAVE;
CHANGE MASTER TO MASTER_DELAY = 100;
START SLAVE;
SHOW SLAVE STATUS\G;
显示
SQL_Delay: 100 --延迟 100S
SQL_Remaining_Delay: NULL
2. 设置取消延迟复制
STOP SLAVE ;
CHANGE MASTER TO MASTER_DELAY=0;
START SLAVE;
SHOW SLAVE STATUS\G;
SQL_Delay: 0 --取消延迟
SQL_Remaining_Delay: NULL
3. 测试
主节点创建库
CREATE DATABASE TEST;
从节点查看
SHOW SLAVE STATUS\G;
.......
SQL_Delay: 100
SQL_Remaining_Delay: 83
Slave_SQL_Running_State: Waiting until MASTER_DELAY seconds after master executed event
.......
4. 参考官网文档
https://dev.mysql.com/doc/refman/5.6/en/replication-delayed.html