开发者

binlog_format = STATEMENT and CURRENT_TIMESTAMP with MySQL replication

can a MySQL slave instance have different row values for the same ID when binlog_format is set to STATEMENT and we insert something like:

insert into foo values(CURRENT_TIMESTAMP)

As I understand it, the slave read the SQL st开发者_Go百科atement and execute it thus, if the replication is lagging, could lead to differences for the same row. Right or wrong ?

How can I avoid this situation ?

Thank you.


Your approach is perfectly safe in statement level replication. The TIMESTAMP is written to the binary log, so the value for CURRENT_TIMESTAMP will be consistent across the master and the slave even if the slave is behind. You can also use the NOW() function safely for the same reason.

The function to avoid is SYSDATE(), which will not use the TIMESTAMP from the binary log, and therefore the slave's value will represent when the statement ran on the slave, rather than when the statement ran on the master.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜