MySQL 5.6 支持延迟复制,可以在Slave服务器指定一个延迟的值。默认值为0秒。使用MASTER_DELAY 选项为CHANGE MASTERTO 设置N秒延迟。
1. 下面来实际演示,正常运行的从节点执行,设置延迟100秒
1
2
3
4
5
6
7
|
STOP SLAVE;
CHANGE MASTER TO MASTER_DELAY = 100;
START SLAVE;
SHOW SLAVE STATUS\G;
显示
SQL_Delay: 100 --延迟 100S
SQL_Remaining_Delay: NULL
|
2. 设置取消延迟复制
1
2
3
4
5
6
|
STOP SLAVE ;
CHANGE MASTER TO MASTER_DELAY=0;
START SLAVE;
SHOW SLAVE STATUS\G;
SQL_Delay: 0 --取消延迟
SQL_Remaining_Delay: NULL
|
3. 测试
1
2
3
4
5
6
7
8
9
|
主节点创建库
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. 参考官网文档
1
|
https:
//dev
.mysql.com
/doc/refman/5
.6
/en/replication-delayed
.html
|
本文转自 roidba 51CTO博客,原文链接:http://blog.51cto.com/roidba/1893340,如需转载请自行联系原作者