There is nothing special about master/master replication in MySQL - it is bidirectional Master/Slave where each server is just a slave of the other server. Otherwise, it behaves exactly as a "regular" master/slave topology. There are some suggestions on how to safeguard this configuration from duplicate primary keys, such as setting an auto_increment_offset
and auto_increment_increment
, only write to one master (run active/passive), and making sure that log_slave_updates
is set.
So, master/master is just master/slave in two directions. Your next question is about how replication works in general, for which you should read this: Replication Implementation Details.
In summary:
- A query executes on the master
- After successful execution, the either the query itself (SBR) or a binary representation of the row(s) affected (RBR) are written into the local binary log along with some metadata.
- On the slave, there is an I/O Thread that runs that connects to the master and streams the master's binary logs and writes them to a local file called the relay log.
- On the slave, the SQL thread reads the relay log and executes the statements contained (SBR)/applies the rows (RBR)
You can see both the I/O thread and the SQL thread active in SHOW SLAVE STATUS and also in the processlist.
In MySQL 5.5, the default is statement based replication. (See Replication Formats)
What you are referring to is Mixed Binary Logging Format which will ordinarily use SBR, but switch to RBR under a number of circumstances where SBR is not considered safe because there is potential for the statement to have different results on the master and the slave. Those are described clearly in the documentation.
Because SBR is the default, in order to use MIXED, you have to explicitly set it in my.cnf
for a persistent change:
binlog_format = MIXED
or dynamically by executing
-- Set binary log format globally
mysql> SET GLOBAL binlog_format = MIXED;
-- set binary log format just for this session
mysql> SET SESSION binlog_format = MIXED;
If you want to set the binlog_format
for a particular statement, you can by setting binlog_format in the session (as shown above) and then executing your statement. However, you have to have SUPER privilege in order to do that, which no application should have. Really, except for certain administrative tasks, there is almost no reason to do that and MIXED replication should be your choice.
I think you should re-initialize your replication.
If the replication worked good, the rows should not be missing. That the rows are missing means there is some inconsistency between your master und your slave. I would not act on the assumption that this is the only error and if I'd fix it by hand everything is back fine again. Instead I would set up the replication from the start again and make sure it stays synced this time, to be sure to get rid of all inconsistencies.
Nevertheless there are some ways to identify which rows are missing. As a starting point you could take a look at this blogpost. This basically includes "decode the relay log" and "search for the current relay log position". One can decode the log for example with this statement:
mysqlbinlog mysql-relay-bin.000001 –base64-output=decode-rows -v > decoded.log
Best Answer
https://dev.mysql.com/doc/refman/8.0/en/replication-features-blackhole.html -->