How a Slave Asks Its Master to Send Its Binary Log MySQL

The slave server must open a normal connection to its master. The MySQL account used to connect to the master must have the REPLICATION SLAVE privilege on the master. Then the slave must send the COM_BINLOG_DUMP command, as in this example taken from function request_dump():

REPLICATION SLAVE

Here variable buf contains the arguments for COM_BINLOG_DUMP. It's the concatenation of:

  • 4 bytes: the position in the master's binlog from which we want to start (i.e. “please master, send me the binlog, starting from this position”).
  • 2 bytes: 0 for the moment.
  • 4 bytes: this slave's server id. This is used by the master to delete old Binlog Dump threads which were related to this slave (see function kill_zombie_dump_threads() for details).
  • variable-sized part: the name of the binlog we want. The dump will start from this binlog, at the position indicated in the first four bytes.

Then send the command, and start reading the incoming packets from the master, like read_event() does (using net_safe_read() like explained below). One should also, to be safe, handle all possible cases of network problems, disconnections/reconnections, malformed events.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

MySQL Topics