MySQL summary (5)-TCL language

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

  1. How does the concurrency problem of services occur?
    When multiple transactions operate on the same data in the same database at the same time
  2. 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

  1. How to solve the concurrency problem Solve the concurrency problem
    by setting the isolation level
  2. Isolation level
    Insert picture description here

Guess you like

Origin blog.csdn.net/qq_43518425/article/details/113787179