2013/11/05

mysql replication logging formats

Starting with version 5.1, MySQL supports three binary logging formats: statement,
row, and mixed.


Row-based logging records raw data about rows in the log. The slave
does not execute the same queries as the master, but instead updates
table rows directly. This is the safest binary logging format because it
can’t insert into the slave table any values that do not exist on the master
.
This format can be used safely even when you call nondeterministic
functions such as NOW().
Statement-based logging just puts queries in the original SQL format
into the log, so the slave executes the same commands as the master. If
you use this format, network traffic usually—although not always—is
much lower than if a row-based format is used because a query can take
up less data than the actual changes it makes to rows
. This is especially
noticeable when you update several rows in a table with BLOB columns.
The disadvantage of this format is that it forces you to ensure data
consistency. For example, if you insert the output of the function
NOW() into a column, you will most likely have different data on the
master and slave.
The mixed binary logging format contains the advantages of both row
and statement logging: it saves the majority of queries in statement
format but switches to row format when a query is not safe, i.e., when
it uses a nondeterministic function such as NOW().