Mysql:Delayed Replication:延迟复制
语法很简单,意义却很重大!
MySQL 5.7 supports delayed replication such that a slave server deliberately lags behind the master by at least a specified amount of time. The default delay is 0 seconds. Use the MASTER_DELAY
option for CHANGE MASTER TO
to set the delay to N
seconds:
CHANGE MASTER TO MASTER_DELAY = N
;
An event received from the master is not executed until at least N
seconds later than its execution on the master. The exceptions are that there is no delay for format description events or log file rotation events, which affect only the internal state of the SQL thread.
Delayed replication can be used for several purposes:
-
To protect against user mistakes on the master. A DBA can roll back a delayed slave to the time just before the disaster.
-
To test how the system behaves when there is a lag. For example, in an application, a lag might be caused by a heavy load on the slave. However, it can be difficult to generate this load level. Delayed replication can simulate the lag without having to simulate the load. It can also be used to debug conditions related to a lagging slave.
-
To inspect what the database looked like long ago, without having to reload a backup. For example, if the delay is one week and the DBA needs to see what the database looked like before the last few days' worth of development, the delayed slave can be inspected.
START SLAVE
and STOP SLAVE
take effect immediately and ignore any delay. RESET SLAVE
resets the delay to 0.
SHOW SLAVE STATUS
has three fields that provide information about the delay:
-
SQL_Delay
: A nonnegative integer indicating the number of seconds that the slave must lag the master. -
SQL_Remaining_Delay
: WhenSlave_SQL_Running_State
isWaiting until MASTER_DELAY seconds after master executed event
, this field contains an integer indicating the number of seconds left of the delay. At other times, this field isNULL
. -
Slave_SQL_Running_State
: A string indicating the state of the SQL thread (analogous toSlave_IO_State
). The value is identical to theState
value of the SQL thread as displayed bySHOW PROCESSLIST
.
When the slave SQL thread is waiting for the delay to elapse before executing an event, SHOW PROCESSLIST
displays its State
value as Waiting until MASTER_DELAY seconds after master executed event
.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)