Surprisingly, that's not gibberish.
That indeed appears at the top of binlogs whenever you do mysqlbinlog to a binary log generated using MySQL 5.1 and MySQL 5.5. You will not see that gibberish in binary logs for MySQL 5.0 and back.
This is why the start point for replication from an empty binary log is
- 107 for MySQL 5.5
- 106 for MySQL 5.1
- 98 for MySQL 5.0 and back
This is good to remember if you do MySQL Replication where the Master if MySQL 5.1 and the slave is MySQL 5.0. This could present a really big headache.
Replication from Master using 5.0 and Slave using 5.1 works fine, not the other way around.(According to MySQL Documentation, it is generally not supported for 3 reasons: 1) Binary Log Format, 2) Row-based Replication, 3) SQL Incompatibility).
Anyway, do a mysqlbinlog on the offending binary log on the master. If the resulting dump produces gibberish in the middle of the dump (which I have seen a couple of times in my DBA career) you may have to skip to position 98 (MySQL 5.0) or 106 (MySQL 5.1) or 107 (MySQL 5.5) of the master's next binary log and start replicating from there (SOB :( you may need to use MAATKIT tools mk-table-checksum and mk-table-sync to reload master changes not on the slave [if you want to be a hero]; even worse, mysqldump the master and reload the slave and start replication totally over [if you don't want to be a hero])
If the mysqlbinlog of the master is completely readable after the top gibberish you saw, it is possible the master's binary log is fine but the relay log on the slave is corrupt (due to transmission/CRC errors). If that's the case, just reload the relay logs by issuing the CHANGE MASTER TO command as follows:
STOP SLAVE;
CHANGE MASTER TO
MASTER_HOST='< master-host ip or DNS >',
MASTER_PORT=3306,
MASTER_USER='< usernmae >',
MASTER_PASSWORD='< password >',
MASTER_LOG_FILE='< MMMM >',
MASTER_LOG_POS=< PPPP >;
START SLAVE;
Where
- MMMM is the last file used from the Master that was last processed on the Slave
- PPPP is the last position used from the Master that was last processed on the Slave
You can get MMMM and PPPP by doing SHOW SLAVE STATUS\G
and using
- Relay_Master_Log_File for MMMM
- Exec_Master_Log_Pos for PPPP
Try it out and let me know !!!
BTW running CHANGE MASTER TO command erases the slave's current relay logs and starts fresh.
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.
Best Answer
When a complex
UPDATE
is run on the master, and it results in only a few rows being updated, then one of these happens:UPDATE
on the Slave. This stalls replication, waiting for the complex query to finish.A simple
UPDATE
that modifies a million rows:DELETE
,INSERT...SELECT
, and a few other things have similar characteristics.I can't be more specific without knowing what, exactly, you were replicating. I hope my examples give you some clues of what could be happening.