mysql cluster 开启binlog日志后将更新操作记录为插入操作

最近在研究mysql集群时发现开启mysql binlog日志后,数据发生update操作时binlog日志里面默认保存的是insert操作。因为我们线上有一台记录所有数据库变更记录的服务器,需要精确了解每台的数据库的数据变化情况。按照现在默认的情况,显然不是我们想要,所以我们还是想在binlog日志文件里面严格区分不同操作事件,在经过操作翻阅官方文档的时候,发现了一个参数

--ndb-log-update-as-write

Command-Line Format --ndb-log-update-as-write
System Variable Name ndb_log_update_as_write
Scope Global
Dynamic Yes
Permitted Values Type boolean
Default ON

The setting of the MySQL Server's --ndb-log-update-as-write option determines whether logging is performed with or without the beforeimage. Because conflict resolution is done in the MySQL Server's update handler, it is necessary to control logging on the master such that updates are updates and not writes; that is, such that updates are treated as changes in existing rows rather than the writing of new rows (even though these replace existing rows). This option is turned on by default; in other words, updates are treated as writes. (That is, updates are by default written as write_row events in the binary log, rather than as update_row events.)

https://dev.mysql.com/doc/mysql-cluster-excerpt/5.6/en/mysql-cluster-replication-conflict-resolution.html#option_mysqld_ndb-log-update-as-write

根据文档描述,mysql cluster sql 节点在启动的时候,会默认开启这个功能。所以我们现在只需要在/etc/my.cnf文件里面将这个选项关闭就可以了

[mysqld]
ndbcluster
ndb-connectstring=localhost
log-bin=mysql-bin
server-id=1
binlog-format=row
ndb-log-update-as-write=off #在配置文件里面将这个选项关闭
[mysql_cluster]
ndb-connectstring=localhost



0条评论