Affairs
Sql statement or a group consisting of one execution unit, the execution unit performs either all, or all not be executed.
Transaction characteristics:
ACID
Atomicity: a transaction can not be subdivided, either perform or not perform
Consistency: a transaction data will perform handover from one consistent state to another consistent state
Isolation: performing a transaction without interference from other transactions
lasting sex: once a transaction is committed, the data will be permanent changes to the database.- Creating a transaction
Implicit transaction: Transaction no apparent opening and closing tags
such as insert, update, delete statement- Explicit transaction: The transaction has a significant opening and mark the end of
the premise: You must set up automatic submission function is disabled, set autocommit = 0;
#步骤1:开启事务
set autocommit=0;
start transaction;可选的
#步骤2:编写事务中的sql语句(select insert update delete)
语句1;
语句2;
...
#步骤3:结束事务
commit;提交事务
rollback;回滚事务
savepoint 节点名;设置保存点
# savepoint 的使用
SET autocommit=0;
START TRANSACTION;
DELETE FROM account WHERE id=25;
SAVEPOINT a;#设置保存点
DELETE FROM account WHERE id=28;
ROLLBACK TO a;#回滚到保存点
- Transaction isolation level:
Dirty read | Non-repeatable read | Magic Reading | |
---|---|---|---|
read uncommitted | √ | √ | √ |
read committed | × | √ | √ |
repeatable read | × | × | √ |
serializable | × | × | × |
The third default mysql isolation level Read Repeatable
Oracle default second read committed isolation level
- To view the isolation level
select @@ tx_isolation; - Setting the isolation level
set session | global transaction isolation level isolation level;