結論:使用--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,如需轉載請自行聯系原作者