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_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.
- 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.