开发者社区 问答 正文

mysql热备如何保证数据的完整性

我希望在热备的情况下,我导下来的数据是事务完整的。

有好的实现吗?

展开
收起
小旋风柴进 2016-03-11 10:36:06 2921 分享 版权
1 条回答
写回答
取消 提交回答
  • 如果要确保事务的完整性(ACID),在使用 mysqldump 进行备份时可以添加 --single-transaction 选项,

      --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.
    
    
    http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html#option_mysqldump_single-transaction

    使用--single-transaction选项进行备份时,且事务分离级别设定为“REPEATABLE READ”时,
    MySQL支持InnoDB表同时写入,但由此会消耗一部分系统资源,因此备份时间会比不使用该选项的时间长。
    如果要使用该选项,建议备份时间安排在相对空闲的时间段。

    另外需要注意的是只有InnoDB和NDB存储引擎支持事务

    2019-07-17 18:58:37
    赞同 展开评论