MySQL5.1 中Innodb事务完整性Bug
今天和 51.com 的 MySQL DBA 景春同学一起遇到了个 MySQL 非常扯淡的Bug:在 5.1 版本中,Innodb 存储引擎如果使用autocommit=0的情况下,单条SQL在执行过程中如果异常中断的话,事务完整性可能无法保证,不论是STATEMENT还是MIXED的binlog_format,都存在相
今天和 51.com 的 MySQL DBA 景春同学一起遇到了个 MySQL 非常扯淡的Bug:在 5.1 版本中,Innodb 存储引擎如果使用autocommit=0的情况下,单条SQL在执行过程中如果异常中断的话,事务完整性可能无法保证,不论是STATEMENT还是MIXED的binlog_format,都存在相同的问题,可以重现,屡试不爽。
测试环境如下:
OS:SunOS 5.10 Generic_137138-09
DB:MySQL 5.1.31/32-log Source distribution
binlog_format:MIXED/STATEMENT
tx_isolation:REPEATABLE-READ
测试脚本如下:
[root@dc-5 /tmp]#cat deletetest.sh
#/bin/sh
mysql -uadmin -h127.0.0.1 -pxxx -e"set autocommit=0;delete from test.test;"
[root@dc-5 /tmp]#cat killtest.sh
#/bin/sh
mysqladmin -uroot processlist |grep "admin"|awk '{print $2}'|xargs mysqladmin -uroot kill
将删除的脚本放到后台执行,然后执行kill脚本:
[root@dc-5 /tmp]#time ./deletetest.sh &
[1] 6708
[root@dc-5 /tmp]#./killtest.sh
ERROR 1053 (08S01) at line 1: Server shutdown in progress
real 0m2.901s
user 0m0.007s
sys 0m0.007s
[root@dc-5 /tmp]#
[1]+ Exit 1 time ./deletetest.sh
到Master 和 Slave 两端分别检查数据,看上去很正常:
root@dc-5 : (none)01:35:43> selectcount(*)fromtest.test;
+----------+
| count(*) |
+----------+
| 1000000|
+----------+
1rowinset(1.71sec)
root@dc-6 : (none)01:36:01> selectcount(*)fromtest.test;
+----------+
| count(*) |
+----------+
| 1000000|
+----------+
1rowinset(1.69sec)
我们再将set autocommit=0拿掉试试看,也就是允许系统自动提交:
[root@dc-5 /tmp]#cat deletetest.sh
#/bin/sh
mysql -uadmin -h127.0.0.1 -pxxx -e"delete from offer1.test;"
[root@dc-5 /tmp]#time ./deletetest.sh &
[1] 6722
[root@dc-5 /tmp]#./killtest.sh
[root@dc-5 /tmp]#ERROR 1053 (08S01) at line 1: Server shutdown in progress
real 0m2.462s
user 0m0.006s
sys 0m0.007s
[1]+ Exit 1 time ./deletetest.sh
再检查 Master 和 Slave 两端的数据:
root@dc-5 : (none)01:40:30> selectcount(*)fromoffer1.test;
+----------+
| count(*) |
+----------+
| 887377 |
+----------+
1rowinset(1.66sec)
root@dc-6 : offer101:44:05> selectcount(*)fromoffer1.test;
+----------+
| count(*) |
+----------+
| 1000000|
+----------+
1rowinset(1.70sec)
Master 和 Slave 两端数据居然出现不一致,在 Master 端已经删除掉了部分数据,在 Slave 端却没有任何变化。执行 deletetest.sh 脚本前后检查 Master 的 Binary Log(SHOW Master STATUS),没有任何变化。这个 Bug 简直是太扯淡了,数据完全没有事务完整性可言了啊。
原文地址:MySQL5.1 中Innodb事务完整性Bug, 感谢原作者分享。

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

As Apple's WWDC conference 2024 came to a successful conclusion, not only macos15 was announced, but the update of Apple's new iOS18 system attracted the most attention. Although there are many new features, as the first version of Apple's iOS18, people inevitably wonder whether it is necessary to upgrade Apple. iOS18, what kind of bugs are there in the latest release of Apple iOS18? After real use evaluation, the following is a summary of Apple iOS18 bugs, let’s take a look. Currently, many iPhone users are rushing to upgrade to iOS18. However, various system bugs are making people uncomfortable. Some bloggers said that you should be cautious when upgrading to iOS18 because "there are so many bugs." The blogger said that if your iPhone is

What do game bugs mean? During the process of playing games, we often encounter some unexpected errors or problems, such as characters getting stuck, tasks being unable to continue, screen flickering, etc. These abnormal phenomena are called game bugs, that is, faults or errors in the game. In this article, we'll explore what game bugs mean and the impact they have on players and developers. Game bugs refer to errors that occur during the development or operation of the game, causing the game to fail to run normally or to behave unexpectedly. These errors may be due to

Lockwaittimeoutexceeded;tryrestartingtransaction - How to solve the MySQL error: transaction wait timeout. When using the MySQL database, you may sometimes encounter a common error: Lockwaittimeoutexceeded;tryrestartingtransaction. This error indicates that the transaction wait timeout. This error usually occurs when

InnoDB is one of the database engines of MySQL. It is now the default storage engine of MySQL and one of the standards for binary releases by MySQL AB. InnoDB adopts a dual-track authorization system, one is GPL authorization and the other is proprietary software authorization. InnoDB is the preferred engine for transactional databases and supports transaction security tables (ACID); InnoDB supports row-level locks, which can support concurrency to the greatest extent. Row-level locks are implemented by the storage engine layer.

MySQL transaction processing: the difference between automatic submission and manual submission. In the MySQL database, a transaction is a set of SQL statements. Either all executions are successful or all executions fail, ensuring the consistency and integrity of the data. In MySQL, transactions can be divided into automatic submission and manual submission. The difference lies in the timing of transaction submission and the scope of control over the transaction. The following will introduce the difference between automatic submission and manual submission in detail, and give specific code examples to illustrate. 1. Automatically submit in MySQL, if it is not displayed

InnoDB is a storage engine that stores data in tables on disk, so our data will still exist even after shutdown and restart. The actual process of processing data occurs in memory, so the data in the disk needs to be loaded into the memory. If it is processing a write or modification request, the contents in the memory also need to be refreshed to the disk. And we know that the speed of reading and writing to disk is very slow, which is several orders of magnitude different from reading and writing in memory. So when we want to get certain records from the table, does the InnoDB storage engine need to read the records from the disk one by one? The method adopted by InnoDB is to divide the data into several pages, and use pages as the basic unit of interaction between disk and memory. The size of a page in InnoDB is generally 16

Title: Windows 11 Memory Integrity is turned off, how to fix it? With the launch of Windows 11, many users have upgraded to the new system. However, some users may encounter problems with Memory Integrity being turned off when using Windows 11, which affects the performance and stability of the computer. This article will discuss the problem of turning off memory integrity in Windows 11 and provide some solutions and suggestions. 1. Causes of Memory Integrity Shutdown Problem in Windows 11

Analysis of solutions to transaction management problems encountered in MongoDB technology development As modern applications become more and more complex and large, the transaction processing requirements for data are also getting higher and higher. As a popular NoSQL database, MongoDB has excellent performance and scalability in data management. However, MongoDB is relatively weak in data consistency and transaction management, posing challenges to developers. In this article, we will explore the transaction management issues encountered in MongoDB development and propose some solutions.
