## 事务的ACID

1、Atomicity原子性

Transactions are often composed of multiple statements. Atomicity guarantees that each transaction is treated as a single "unit", which either succeeds completely, or fails completely: if any of the statements constituting a transaction fails to complete, the entire transaction fails and the database is left unchanged. An atomic system must guarantee atomicity in each and every situation, including power failures, errors and crashes.

2、Consistency一致性

Consistency ensures that a transaction can only bring the database from one valid state to another, maintaining database invariants: any data written to the database must be valid according to all defined rules, including constraints, cascades, triggers, and any combination thereof. This prevents database corruption by an illegal transaction, but does not guarantee that a transaction is correct.

3、Isolation隔离性

Transactions are often executed concurrently (e.g., reading and writing to multiple tables at the same time). Isolation ensures that concurrent execution of transactions leaves the database in the same state that would have been obtained if the transactions were executed sequentially. Isolation is the main goal of concurrency control; depending on the method used, the effects of an incomplete transaction might not even be visible to other transactions.

4、Durability持久性

Durability guarantees that once a transaction has been committed, it will remain committed even in the case of a system failure (e.g., power outage or crash). This usually means that completed transactions (or their effects) are recorded in non-volatile memory.

（1）事务的并发执行

（2）事务故障或系统故障。

## 隔离级别

1、read uncommitted

2、read commited

3、repetable read

4、serializable

mysql默认是repetable read，所以为了保证事务中每个select是可以重复读的，select 的表会被锁住，这样当使用

update ..select * from
insert into ...select * from 

show global variables like '%isolation%';
set global transaction_isolation='read-commited';

## mysql日志

1、binlog

binlog常用来进行数据恢复、数据复制。

2、redo log

3、undo log