I have MySQL Master-Master replication on 2 servers.
I want to replicate to another slave server.
When I configure the slave to replicate from master1
, only data added on master1
is replicated. When I added a record on master2
, the record is replicated to master1
but not replicated to the slave.
Any idea how to solve this?
- m1
server_id = 1
log_slave_updates = OFF
- m2
server_id = 23
log_slave_updates = OFF
- s3
server_id = 21
log_slave_updates = OFF
Best Answer
The Problem
The server option
log_slave_updates
needs to be enabled on both m1 and m2The Solution
Please add the following in /etc/my.cnf on both m1 and m2
then run this on both m1 and m2
The Reason
Let's use your example above
m1
is Master ofm2
m1
is Master ofs3
m2
is Master ofm1
Here is what happens when you run
INSERT INTO mydb.mytable ...
onm1
m2
executesINSERT
m2
recordsINSERT
into the current binary log along with server_id=23m1
retrievesINSERT
fromm2
via I/O Threadm1
recordsINSERT
via I/O Thread into lastest relay logm1
retrievesINSERT
from relay log via SQL Thread and examines its server_idm1
sees that the server_id of theINSERT
is 23 which is not the same asm1
's server_id (1)m1
executesINSERT
OK, all well and good. But, why doesn't
s3
get to receive anything? Becauselog_slave_updates
is not enabled,m1
does not save theINSERT
and the original server_id posting theINSERT
into its own binary logs.If
log_slave_updates
was enabled onm1
, now follow along your example and let's see what should happen:m2
executesINSERT
m2
recordsINSERT
into the current binary log along with server_id=23m1
retrievesINSERT
fromm2
via I/O Threadm1
recordsINSERT
via I/O Thread into lastest relay logm1
retrievesINSERT
from relay log via SQL Thread and examines its server_idm1
sees that the server_id of theINSERT
is 23 which is not the same asm1
's server_id (1)m1
executesINSERT
m1
recordsINSERT
into the current binary log along with server_id=23s3
retrievesINSERT
fromm1
via I/O Threads3
recordsINSERT
via I/O Thread into lastest relay logs3
retrievesINSERT
from relay log via SQL Thread and examines its server_ids3
sees that the server_id of theINSERT
is 23 which is not the same ass3
's server_id (21)s3
executesINSERT
This fully explains why
s3
never sees anything fromm2