[MySQL] Binlog three formats Introduction and Analysis

There are three mysql binlog log statement row mixed.

Statement

Each sql will modify the data recorded in the binlog.

Advantages: the variation of each row need not be recorded, reducing the amount of log binlog, the IO savings, improved performance. (Row number as compared to the amount of energy saving performance logs, depending on the SQL application, the normal edit or insert the same amount of log record format generated row is less than the amount of logs Statement also generated, but if considering the update conditions with operation, as well as delete the entire table, alter table and other operations, ROW format will produce a large log, and therefore should be considered according to the actual situation with the application, log the amount they produce will increase the number of whether to use the ROW format of the log, and brought IO performance problems.)

Cons: Since only execute the statement, these statements in order to run properly on the slave, each statement must also record some information in the course of implementation, in order to ensure that all statements get executed in the master and slave in the end, when the same record the result of. In addition mysql replication, as some specific functions function, slave and the master can be consistent there will be many related issues (such as sleep () function, last_insert_id (), as well as user-defined functions (udf) problem occurs).

The following functions can not be copied statement:

  • LOAD_FILE()

  • UUID()

  • USER()

  • FOUND_ROWS()

  • SYSDATE () (unless startup is enabled --sysdate-is-now option)

And it will produce more than RBR row-level locking in INSERT ... SELECT

Row

Sql statement is not recorded context information, which saves only the modified records.

Pros: context-sensitive information can not be recorded in the binlog sql statement is executed, only need to record that a record is modified into anything. So log content rowlevel record will be very clear details of each line of data modifications under. And the process will not be stored under certain specific circumstances, or function, and the problems trigger the call and triggers can not be reproduced correctly

Cons: All statements executed when logged when all will modify each line to record the record, this may generate a lot of log content, such as an update statement to modify multiple records in each of the binlog changes will be recorded, so causing binlog log will have a significant amount, especially when performing such alter table statements, due modify table structure, each record is changed, then the table each record will be logged .

Mixedlevel:

Is a mixture of two or more kinds of level, using the general statement modifies the binlog statment save format, such as some functions, statement can not be completed from the master copy operation, the row format is used to save binlog, MySQL based on each specific sql statement executed to distinguish between the log form of treatment records, that is, between the Statement Row and select a new version of MySQL squadron row level mode has also been optimized, not all modifications are to row level to record, as encountered table when structural changes will be recorded in a statement mode. As for statements such as update or delete data modification, or it will record changes for all rows.

Binlog formulated with basic formatting

Mysql BInlog log format can be specified by binlog_format property my.cnf file mysql. Such as the following:

binlog_format = MIXED // binlog log format

log_bin = directory /mysql-bin.log // binlog log name

expire_logs_days = 7 // binlog clean-up time expired

max_binlog_size 100m // binlog each log file size

Binlog log format options:

Statement Mysql default is to use the log format is recommended MIXED.

Due to some special use, consider using ROWED, such as to modify their own data synchronization via binlog log, it would save a lot of related operations. For binlog data processing will become very easy, relatively mixed, resolution is also very easy (of course, provided that the amount of log increase brought about by the IO overhead can be within a tolerable range).

mysqlbinlog format selection:

mysql log format for the selected principle: If case of using INSERT, UPDATE, DELETE and so direct the operation table, the log recording format set according binlog_format, if employed GRANT, REVOKE, SET PASSWORD statement managed to do other words , then in any case the use of SBR recording mode

Published 349 original articles · won praise 14 · views 90000 +

Guess you like

Origin blog.csdn.net/LU_ZHAO/article/details/105305180