The transaction database: Object Transaction set of operations is composed of a single logical unit of data, and the database is a database ultimate goal is to convert from one consistent state to another consistent state.
Four characteristics of the transaction (ACID):
- All database operations atomicity Atomicity things contained either all succeed, or all fail rollback
- Consistency Consistency before and after the execution of a transaction must be in a consistent state
- Business isolation Isolation a result uncommitted transactions are not visible to other transactions
- Persistent Durability Once a transaction is submitted that changes to the data in the database is permanent
Database security issues when reading and writing:
- A dirty read transaction data is being used but not yet committed, another transaction B also have access to this data, but also the use of this data.
- A non-repeatable read transaction data in a multiple operation, in the middle of these two or more times to access the data, the data object B also operates, and its value has changed, which leads to the same transaction twice A the operation of this data when the value is not the same, which is non-repeatable read.
- Phantom read transaction produced a phenomenon does not perform independently. A plurality of read line transaction matches the search criteria, and other transaction B to insert or delete transaction method to modify the result set A, and then submitted. A result of this will lead original execution comprises execution result B, the two originally irrelevant, it is equivalent to A hallucination.
Four isolation level of the database (concurrent transactions):
- You can read uncommitted Read uncommited write transaction to prevent other write transactions to avoid missing update. But it does not prevent other read transaction.
- Read commited readable submitted written things will prevent other read and write transactions, read transaction will not prevent any other transaction.
- Repeatable read Repeatable read read things that will prevent other write transactions, but does not prevent other read transaction. MySql default isolation level.
- Serialization Serializable phantom read can be avoided. Reading shared locks, plus exclusive write locks.
The four isolation levels can deal with the problem are:
reference:
https://blog.csdn.net/qq_34569497/article/details/79064208