MySQL InnoDB是如何实现ACID的?

The ACID model is a set of database design principles that emphasize aspects of reliability that are important for business data and mission-critical applications. MySQL includes components such as the InnoDB storage engine that adhere closely to the ACID model so that data is not corrupted and results are not distorted by exceptional conditions such as software crashes and hardware malfunctions. When you rely on ACID-compliant features, you do not need to reinvent the wheel of consistency checking and crash recovery mechanisms. In cases where you have additional software safeguards, ultra-reliable hardware, or an application that can tolerate a small amount of data loss or inconsistency, you can adjust MySQL settings to trade some of the ACID reliability for greater performance or throughput.

ACID 模型是一组数据库设计原则,强调对于业务数据和关键任务应用程序而言重要的可靠性方面。MySQL 包括诸如 InnoDB 存储引擎等组件,严格遵循 ACID 模型,以确保数据不会因软件崩溃和硬件故障等异常情况而损坏,并且结果不会被扭曲。当您依赖符合 ACID 标准的特性时,您无需重新设计一致性检查和崩溃恢复机制。在某些情况下,如果您有额外的软件保护措施、超可靠的硬件或可以容忍少量数据丢失或不一致性的应用程序,您可以调整 MySQL 设置,以牺牲一部分 ACID 可靠性来换取更高的性能或吞吐量。

Question1:ACID分别代指什么?

  • Atomicity 原子性

  • Consistency 一致性

  • Isolation 隔离性

  • Durability 持久性

Question2:MySQL如何实现?

Atomicity 原子性

通过Transaction(事务)实现,保证同一个事务内的一组操作,要么一起成功提交,要么一起失败回滚

Consistency 一致性

通过Doublewrite Buffer(双写缓冲区)保证数据的完整写入硬盘,在异常场景下,服务崩溃、主机异常关机等,通过crash recovery(异常恢复)机制保证数据的完整

Isolation隔离性

通过事务隔离级别+多种锁机制保证数据隔离性

Durability持久性

持久性的保证是个庞大的系统,简单从几个方面阐述:

1、通过Doublewrite Buffer(双写缓冲区)保证数据的完整写入硬盘

2、数据刷盘策略 innodb_flush_log_at_trx_commit variable

https://dev.mysql.com/doc/refman/8.0/en/innodb-parameters.html#sysvar_innodb_flush_log_at_trx_commit

3、binlog日志

4、表空间隔离

你可能感兴趣的:(数据库,mysql,adb,数据库)