天天看点

--single-transaction 参数对应MyISAM引擎和InnoDB引擎

结论:使用--single-transaction 备份含有MyISAM的表不会获得一致性备份,所有的innodb表可以获得事务开始时的一致性快照,但是MyISAM表获取的是备份该表时的最新快照,

测试库:test,包含表t1,t2,t3,t4,t5,t6  除t6是MyISAM表之外,其他均为innodb表

表t1,t2 数据量相同,均为288W,其他t3,t4,t5,t6 均只含几条记录

控制台:

mysqldump -uxx -pxx --single-transaction test >test.sql 

mysql客户端:

mysql>insert into t6 values(15);  //t6是MyISAM表 

第一次实验:

在控制台发出第一条命令,停留5s,在mysql客户端发出第二条命令,但是保证第二条命令式在第一条命令还未结束时发出,这样可以基本保后一个事务是在第一个事务之后发生,在备份文件中能够找到t6的记录15,

读取的是备份该表时的最新“快照”

mysql>insert into t5 values(15);  //t5是innodb表

第二次实验:

在控制台发出第一条命令,停留5s,在mysql客户端发出第二条命令,但是保证第二条命令式在第一条命令还未结束时发出,这样可以基本保后一个事务是在第一个事务之后发生,在备份文件中不能够找到t5的记录15,

读取的是备份开始时的快照

--single-transaction 

                      Creates a consistent snapshot by dumping all tables in a

                      single transaction. Works ONLY for tables stored in

                      storage engines which support multiversioning (currently

                      only InnoDB does); the dump is NOT guaranteed to be

                      consistent for other storage engines. While a

                      --single-transaction dump is in process, to ensure a

                      valid dump file (correct table contents and binary log

                      position), no other connection should use the following

                      statements: ALTER TABLE, DROP TABLE, RENAME TABLE,

                      TRUNCATE TABLE, as consistent snapshot is not isolated

                      from them. Option automatically turns off --lock-tables.

      本文转自Tenderrain 51CTO博客,原文链接:http://blog.51cto.com/tenderrain/1602182,如需转载请自行联系原作者

继续阅读