Mysql Binlog three formats Details

There are different modes binlog What difference does it make?

1.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).

2.Row: sql statement does not record contextual 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 .

3.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 will be performed according to each one specific sql statement to distinguish between the log form of treatment records, that is, choose one between the statement and Row. the new version of MySQL squadron row level mode has also been optimized, not all changes will be recorded in a row level, like when it came to the table structure 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

1. Basic preparation

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

 

2.Binlog log format selected

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). 

3.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

4.Mixed log Description:

In slave synchronization log, using a function such time now, MIXED log format, generates the corresponding time unix_timestamp string () * 1000 in the log, upon completion of the synchronization slave, the access time occurs sqlEvent to ensure the accuracy of the data. In addition to some of the functionality slave functions corresponding to complete data synchronization, and for some of the above-specified UDF similar functions, can not lead to Slave known, the format will be employed ROW Binlog storage, can be produced to ensure Binlog for complete Slave data synchronization.

Guess you like

Origin www.cnblogs.com/dbalightyear/p/11261771.html