The Binary Log MySQL

When started with --log-bin, mysqld creates a binary log (“binlog”) of all updates. Only updates that really change the data are written (a DELETE issued on an empty table won't be written to the binary log). Every query is written in a packed form: an event. The binary log is a sequence of events. The mysqlbinlog utility can be used to print human-readable data from the binary log.

replicationreplicationreplication

Here are the possible types of events:

possible types of eventspossible types of events

  • START_EVENT
  • Written when mysqld starts.
  • STOP_EVENT
  • Written when mysqld stops.
  • QUERY_EVENT
  • Written when an updating query is done.
  • ROTATE_EVENT
  • Written when mysqld switches to a new binary log (because someone issued FLUSH LOGS or the
    current binary log's size becomes too large. The maximum size is determined as described in Section
  • CREATE_FILE_EVENT
  • Written when a LOAD DATA INFILE statement starts.
  • APPEND_BLOCK_EVENT
  • Written for each loaded block.
  • DELETE_FILE_EVENT
  • Written if the load finally failed
  • EXECUTE_LOAD_EVENT
  • Written if the load finally succeeded.
  • SLAVE_EVENT
  • Not used yet.
  • INTVAR_EVENT, RAND_EVENT, USER_VAR_EVENT
  • Written every time a query or LOAD DATA used them. They are written together with the
    QUERY_EVENT or the events written by the LOAD DATA INFILE. INTVAR_EVENT is in fact
    two types: INSERT_ID_EVENT and LAST_INSERT_ID_EVENT.
  • INSERT_ID_EVENT
  • Used to tell the slave the value that should be used for an auto_increment column for the next
    query.
  • LAST_INSERT_ID_EVENT
  • Used to tell the slave the value that should be used for the LAST_INSERT_ID() function if the next query uses it.
  • RAND_EVENT
  • Used to tell the slave the value it should use for the RAND() function if the next query uses it.
  • USER_VAR_EVENT
  • Used to tell the slave the value it should use for a user variable if the next query uses it.

The event's format is described in details “Replication Event Format in Detail”.

There is a C++ class for every type of event (class Query_log_event etc). Prototypes are in sql/log_event.h. Code for methods of these classes is in log_event.cc. Code to create, write, rotate, or delete a binary log is in log.cc.


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

MySQL Topics