Article Directory
1. Meaning
Transaction: one or more SQL statements form an execution unit, a group of SQL statements are either executed or not executed
2. Features (ACID)
A Atomicity: A transaction is an indivisible whole, either all executed or not executed
C Consistency: A transaction can switch data from one consistent state to another consistent state
I Isolation: A transaction is not affected by other transactions Interference, multiple transactions are isolated from each other
D persistence: once a transaction is submitted, it will be permanently persisted to the local
Three, the use of affairs steps★
Understanding:
implicit (automatic) transaction: there is no obvious opening and ending, it is a transaction that can be automatically submitted, such as insert, update, delete
Explicit transaction: with obvious opening and ending
Use explicit transaction: ①Open
transaction
set autocommit=0;
start transaction; #can be omitted
②Write a set of logical SQL statements
Note: SQL statements support insert, update, and delete
Set the rollback point:
savepoint rollback point name;
③End the transaction
Submit: commit;
rollback: rollback;
rollback to the specified place: rollback to rollback rollback;
Four, concurrent transactions
- How does the concurrency problem of services occur?
When multiple transactions operate on the same data in the same database at the same time - What are the concurrency problems?
Dirty read: A transaction reads data that has not yet been committed by other transactions, and it reads data "updated" by other transactions.
Non-repeatable read: One transaction reads multiple times, but the result is different.
Phantom read: One transaction reads the other The transaction has not yet committed the data, but what is read is the data "inserted" by other transactions
- How to solve the concurrency problem Solve the concurrency problem
by setting the isolation level - Isolation level