MySQL Replication: Can a Slave Server Simultaneously Act as Master in a Daisy-Chained Setup?


3 views

In MySQL replication architectures, it's indeed possible to configure a slave server to act as a master for another slave, creating what we call a "daisy-chained" replication topology. Your current setup with DB1→DB2→DB3→DB4 is technically feasible, but requires proper configuration of several key parameters.

The reason DB2's binlog position isn't changing likely stems from its default configuration. By default, MySQL slaves don't log their replicated events to their own binary logs. To enable this behavior, you need to modify these critical parameters in DB2's my.cnf:

[mysqld]
log-bin = mysql-bin
log-slave-updates = ON
server-id = 2  # Must be unique in your replication topology

Here's how to properly set up the daisy chain replication:

# On DB2 (current slave/future intermediate master):
STOP SLAVE;
CHANGE MASTER TO MASTER_HOST='DB1', ... # Existing configuration
START SLAVE;

# On DB3 (new master for DB4):
CHANGE MASTER TO 
MASTER_HOST='DB2',
MASTER_USER='repl_user',
MASTER_PASSWORD='securepassword',
MASTER_LOG_FILE='mysql-bin.000020',  # From DB2's SHOW MASTER STATUS
MASTER_LOG_POS=98;                   # Initial position from DB2
START SLAVE;

After configuration, verify the replication status on each server:

SHOW SLAVE STATUS\G
SHOW MASTER STATUS;
SHOW PROCESSLIST;

Key metrics to monitor include:

  • Seconds_Behind_Master on all slaves
  • Slave_IO_Running and Slave_SQL_Running status
  • Replication lag metrics

While this setup works, consider these operational aspects:

# Potential issues:
1. Increased latency as writes propagate through the chain
2. Single point of failure if DB2 goes down
3. More complex troubleshooting when issues occur

# Mitigation strategies:
- Implement semi-synchronous replication
- Monitor replication lag aggressively
- Consider GTID-based replication for easier failover

For production environments, you might consider a more resilient setup:

# Multi-source replication where DB3 replicates from both DB1 and DB2
# This provides better fault tolerance
CHANGE MASTER TO MASTER_HOST='DB1' FOR CHANNEL 'master1';
CHANGE MASTER TO MASTER_HOST='DB2' FOR CHANNEL 'master2';
START SLAVE FOR CHANNEL 'master1';
START SLAVE FOR CHANNEL 'master2';

A common MySQL replication scenario involves setting up an intermediate master server that acts both as a slave (receiving data) and master (sending data). This configuration is particularly useful during database migrations or when implementing multi-tier replication architectures.

By default, MySQL slaves don't enable binary logging. For DB2 to function as both slave and master:

# In DB2's my.cnf configuration file
[mysqld]
log-bin=mysql-bin
log-slave-updates=1
server-id=2  # Must be unique across all servers

Here's how to properly configure your daisy chain replication:

-- On DB2 (intermediate master):
STOP SLAVE;
CHANGE MASTER TO MASTER_HOST='DB1';
START SLAVE;

-- On DB3:
CHANGE MASTER TO MASTER_HOST='DB2', 
MASTER_USER='repl_user', 
MASTER_PASSWORD='password',
MASTER_LOG_FILE='mysql-bin.000020', 
MASTER_LOG_POS=98;
START SLAVE;

After configuration, verify the replication status on all servers:

SHOW SLAVE STATUS\G
SHOW MASTER STATUS;

For production environments with heavy write loads:

  • Monitor replication lag carefully in chained setups
  • Consider using GTID-based replication for easier failover
  • Configure proper slave_parallel_workers for performance

If replication breaks in the chain:

-- Check for errors:
SHOW SLAVE STATUS\G

-- Common fixes:
SET GLOBAL sql_slave_skip_counter = 1;
START SLAVE;