MySQL 主从复制事件校验 mysql Replication Event Checksum
mysql 主从复制(replication) 同步速度快,简单易用,并且相当可靠。不过,当你检查到主从数据不一致的时候,很难判断出问题所在
mysql 主从复制(replication) 同步速度快,简单易用,并且相当可靠。
不过,当你检查到主从数据不一致的时候,很难判断出问题所在(软件问题?硬件问题?网络传输问题?)
一个比较常见的情况是软硬件或者网络传输出错,导致主服务器上运行的sql语句与从服务器上运行的sql语句不一致(称为event corrupt)。
为了解决这个问题, mysql的开发人员在 5.6 Milestone Development Release版本中加入了 replication event checksum(主从复制事件校验)功能。
相关阅读:
MySQL 5.6主从复制第一部分[简介及配置]
MySQL 5.6主从复制第二部分[恢复某一台从服务器]
MySQL 5.6主从复制第三部分[把从服务器提升为主服务器]
MySQL 5.6主从复制第四部分[一些被忽视的操作细节]
MySQL 主从复制事件校验 MySQL Replication Event Checksum
使用pt-table-checksum检查主从复制是否正常
----------------------------------------分割线----------------------------------------
当一个event被写入binary log(二进制日志)的时候,checksum也同时写入binary log,然后在event通过网络传输到从服务器(slave)之后,再在从服务器中对其进行验证并写入从服务器的relay log.
由于每一步都记录了event和checksum,所以我们可以很快地找出问题所在。
checksum使用zlib中的CRC-32算法,更具体地讲,是ISO-3309 CRC-32算法,虽然此算法效率非常高,但总是带来了一些额外的计算,至于会影响性能到怎样的地步,目前还没有benchmark。
[图1]
如图1所示,当箭头离开thread的时候,就可以生成checksum;当箭头进入thread的时候,就可以对checksum进行校验了。
不过由于某些原因,并非在所有的箭头处都进行了checksum。
event checksum功能,引入了三个新的参数:
binlog_checksum
默认为NONE, 表示在图1的箭头1 不生成checksum, 这样就可以兼容旧版本的mysql。
此外,就只能设置为CRC32了。
master_verify_checksum
可以设置为0或者1(默认为0)。 对应于图1中的箭头2。
设置为1的话,不仅dump thread会对event进行校验,当master上执行show binlog events的时候,也会对event进行校验。
设置为1,可以保证event被完整无缺地写入到主服务器的binlog中了。
不过,通常这个都设置为0。
slave_sql_verify_checksum
与master_verify_checksum类似,这个也只能设置为0或者1(默认为1)。
设置为1, 在图1的箭头4处会生成checksum,然后在箭头5处会对checksum进行验证。
看完这三个参数,再与图1进行一下比较,会发现在箭头3那里没有进行任何验证。
原文中的解释是:
在箭头4的时候,当IO thread把event写入到relay log的时候,会验证checksum。
This is not necessary since the checksum is verified when the event is written to the relay log at point 4, and the I/O thread just does a straight copy of the event。
当checksum出错的时候,会是怎样的呢?试试看吧。
mastert1 name ; Query OKaffected (0.04 sec) mastert1; Query OKaffected (0.00 sec) Records: 2 Duplicates: 0 Warnings: 0 master; Log_name masterQuery masterIntvar INSERT_IDmasterQuery ; masterQuery COMMIT sec)这里与老版本的mysql一致,, 暂时还看不到checksum的影子。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Data backup and failure recovery: Discussion on the importance of MySQL master-slave replication in cluster mode Introduction: In recent years, with the continuous growth of data scale and complexity, database backup and failure recovery have become particularly important. In distributed systems, MySQL master-slave replication is widely used in cluster mode to provide high availability and fault tolerance. This article will explore the importance of MySQL master-slave replication in cluster mode and give some code examples. 1. Basic principles and advantages of MySQL master-slave replication MySQL master-slave replication is a general

Optimizing database performance: The best way to use MySQL master-slave replication in cluster technology Abstract: With the rapid development of the Internet, database performance issues have become the focus of various enterprises and organizations. MySQL master-slave replication technology plays an important role in solving database performance bottlenecks. This article will introduce the concepts and principles of MySQL master-slave replication, as well as the best use methods in cluster technology, to help readers optimize database performance. 1. Introduction As the amount of data continues to increase, database performance problems have become increasingly prominent. How to optimize numbers

Decrypting MySQL master-slave replication: Revealing its key implementation mechanism in cluster mode Introduction: In modern database systems, high availability and flexibility of data are very important. As an open source relational database management system, MySQL has a wide range of applications in meeting user needs. MySQL's master-slave replication is a very critical part of the MySQL database architecture and is used to achieve data backup and high availability. This article will focus on revealing the key implementation mechanism of MySQL master-slave replication, especially in cluster mode.

Cope with high concurrency with ease: Analysis of the performance advantages of MySQL master-slave replication as a cluster technology. With the rapid development of the Internet, user visits to websites and applications have shown an explosive growth trend. In this high-concurrency situation, how to ensure system stability and performance has become an important task for every developer and system administrator. In databases, MySQL master-slave replication technology is widely used and has become one of the effective solutions to deal with high concurrency. This article will explore the performance advantages of MySQL master-slave replication as a cluster technology. first

Is MySQL master-slave replication a cluster technology or a load balancing technology? Summary of analysis and differences: MySQL master-slave replication is a database replication technology used to synchronize database data on multiple servers. This article will analyze and distinguish the differences between MySQL master-slave replication, cluster technology and load balancing technology in terms of technical principles, application scenarios and functional characteristics. Introduction: In modern Internet applications, high availability and scalability of databases are crucial. MySQL master-slave replication is one of the common solutions, however,

Detailed explanation of the functions and advantages of MySQL master-slave replication in cluster technology Introduction MySQL is a powerful relational database management system that is widely used in various large-scale websites and applications. As the amount of data increases and access requests increase, the pressure on a single MySQL server gradually increases. In order to improve the performance and reliability of the database, people begin to adopt cluster technology, among which MySQL master-slave replication is one of the commonly used technologies. means. MySQL master-slave replication principle MySQL master-slave replication refers to the

Tapping into the cluster technology potential of MySQL master-slave replication: Comparative evaluation of open source solutions and commercial solutions. With the continuous development of Internet business and the increasing amount of data, the demand for database cluster solutions has become increasingly strong. MySQL master-slave replication technology just meets this demand. It can process the read and write operations of the database separately on multiple nodes, improving the read performance and availability of the database. This article will explore the potential of cluster technology in MySQL master-slave replication, and conduct a comparative evaluation of open source solutions and commercial solutions.

With the rapid development of the Internet, the amount of data in application systems is increasing, and the requirements for database performance and reliability are also getting higher and higher. As one of the most commonly used open source relational databases, MySQL has high performance and stability and is widely used in various enterprise-level applications. As a commonly used data replication solution, MySQL master-slave replication can improve data reliability and read and write performance, and is widely used in large-scale data applications. The cluster feature of MySQL master-slave replication refers to synchronizing the data of the master database through the replication mechanism.
