How to Use Percona Toolkit to solve the problem of Mysql master non-synchronization (1)

Source: Internet
Author: User
Tags percona

How to Use Percona Toolkit to solve the problem of Mysql master non-synchronization (1)

For various reasons, data inconsistency often occurs in the mysql Master/Slave architecture, which is roughly attributed to the following categories:

  • 1: write data to the slave Database
  • 2: Execute non-deterministic query
  • 3: Roll Back transactions with mixed transaction tables and non-transaction tables
  • 4: binlog or relay log data corruption

The danger of data synchronization to applications is fatal. When the Master/Slave Data is inconsistent, the common solution is to take the slave database offline first, then, we can find a third time in the middle of the night to stop the application and re-execute the synchronization. If the database volume is very large, the workload can be imagined and people will crash. This article describes how to use percona-toolkit to check and re-Synchronize the synchronization status of the mysql master-slave database.

I. Install percona-toolkit

 
 
  1. # yum -y install perl-Time-HiRes 
  2. # wget 
  3. http://www.percona.com/downloads/percona-toolkit/2.2.13/tarball/percona-toolkit-2.2.13.tar.gz 
  4. # tar -zxvpf percona-toolkit-2.2.13.tar.gz 
  5. # cd percona-toolkit-2.2.13 
  6. # perl Makefile.PL 
  7. # make 
  8. # make install 

Ii. Modify the binlog_format parameter of mysql to the row format.

Mysql binlog has three formats: Statement, Mixed, and ROW!

1. Statement:

Each SQL statement that modifies the data is recorded in the binlog.

Advantage: you do not need to record changes in each row, which reduces the binlog volume, saves IO, and improves performance. (The performance and log volume can be reduced compared to the row, which depends on the application's SQL condition. The log volume generated by modifying the same record normally or inserting the row format is smaller than the log volume generated by Statement, however, considering the conditional update operations, as well as the entire table deletion and alter TABLE operations, the ROW format will generate a large number of logs, therefore, when considering whether to use the ROW format log, it should be based on the actual situation of the application, the amount of logs generated will increase, and the IO performance problems .)

Disadvantage: Because only execution statements are recorded, in order that these statements can run correctly on slave, some related information of each statement must be recorded during execution, to ensure that all the statements can get the same results as the execution on the master end in slave. In addition, mysql replication, such as some specific function functions, slave can be consistent with the master, there will be many related problems (such as sleep () function, last_insert_id (), and user-defined functions (udf) problems ).

2. Row

The context information of the SQL statement is not recorded. Only the record that is saved is modified.

Advantage: binlog does not record the context-related information of the executed SQL statement. You only need to record what the record is modified. Therefore, rowlevel logs Clearly record the details of each row of data modification. In addition, there will be no problems in certain situations where stored procedures, functions, trigger calls and triggers cannot be correctly copied.

Disadvantage: When all statements executed are recorded in the log, they are all recorded with modifications recorded in each line. This may produce a large amount of log content, such as an update statement, if you modify multiple records, each modification to the binlog will be recorded, resulting in a large amount of binlog logs. Especially when you execute statements such as alter table, because of the table structure modification, if each record changes, each record in the table is recorded in the log.

3. Mixed

The preceding two levels are used in combination. For general statement modification, binlog is saved in statment format. For example, if statement cannot complete master-slave replication, binlog is saved in row format, mySQL will differentiate the log format of the Record Based on each specific SQL Statement executed, that is, select one between Statement and Row. the row level mode of the new MySQL squadron is also optimized. Not all modifications are recorded by row level, as if the table structure is changed, it will be recorded in statement mode. For statements that modify data such as update or delete, changes to all rows are recorded.

Modify the configuration items of the my. cnf file in the Master/Slave database as follows:

 
 
  1. binlog_format=ROW


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.