我想澄清一点困惑。我有一个 master + slaves 设置。我有一个主人,三个奴隶。所有写入 (INSERT|UPDATE|DELETE
) 都交给 master。所有读取 (SELECT
) 都转到随机选择的其中一个从站。我的所有表都使用 InnoDB 存储引擎。
我很好奇 MySQL/InnoDB 在此设置中如何处理事务。如果 MySQL 将事务中的每个更改写入 binlog,那么一切都应该没问题。但是,如果在提交事务之前不写入二进制日志,我可以看到存在一些大问题。
任何人都可以解释在复制到位的事务期间 MySQL 中发生了什么吗?
最佳答案
根据 this , slave 只能在事务提交后才能看到变化。
Transactions that fail on the master do not affect replication at all. MySQL replication is based on the binary log where MySQL writes SQL statements that modify data. A transaction that fails (for example, because of a foreign key violation, or because it is rolled back) is not written to the binary log, so it is not sent to slaves.
和this确认:
The binary log is crash-safe. Only complete events or transactions are logged or read back.
关于mysql - 事务和主从复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6969433/