当前位置:网站首页>Database transaction Transanction
Database transaction Transanction
2022-06-24 22:42:00 【Passerby Chen】
What is business transanction ?
Business , A logical set of operations , The units that make up this set of operations are either all successful , All or nothing .
The role of affairs : Ensure that a set of operations all succeed or fail .
Business (transanction) Four characteristics of ( ACID ): Atomicity (Atomicity)、 Uniformity (Correspondence)、 Isolation, (Isolation)、 persistence (Durability).
Atomicity (Atomicity) | All operations in the whole transaction , Or it's all done , Or not at all , It's impossible to stop in the middle | Or they all succeed , Or they all fail |
Uniformity (Correspondence) | Before and after transaction start , The database integrity constraint is not broken | The integrity of the data before and after the transaction must be consistent |
Isolation, (Isolation) | Isolated state execution transactions , Make them seem like the only operations that the system performs at a given time | Transactions do not interfere with each other |
persistence (Durability) | After the transaction is completed , Changes made by the firm to the database are persisted in the database , It will not be rolled back | Persistence means that once a transaction is committed , It changes the data in the database permanently |
How things work

Four isolation levels of transactions
| Level | name | Isolation level | Dirty reading | It can't be read repeatedly | Fantasy reading | Database default isolation level |
|---|---|---|---|---|---|---|
| 1 | Read uncommitted | read uncommitted | yes | yes | yes | |
| 2 | Read submitted | read committed | no | yes | yes | Oracle |
| 3 | Repeatable | repeatable read | no | no | yes | MySQL |
| 4 | Serialization | serializable | no | no | no |


Set isolation level
Query the current transaction isolation level
select @@tx_isolation;
Set the transaction isolation level
set session transaction isolation level Isolation level ; eg: Set the transaction isolation level to :read uncommitted,read committed,repeatable read,serializable eg: set session transaction isolation level read uncommitted;
Manual transaction management
Mode one : The way to manually start a transaction 【 master 】
start transaction; Open transaction
commit; Submit
rollback; Roll back-- scene : zs towards ls Transfer accounts 100 element -- No abnormal -- Open transaction start transaction; -- zs money -100 update account set money = money - 100 where name = 'zs'; -- ls money +100 update account set money = money + 100 where name = 'ls'; -- Commit transaction commit; -- There are abnormal -- Open transaction start transaction; -- zs money -100 update account set money = money - 100 where name = 'zs'; -- An exception may occur here -- ls money +100 update account set money = money + 100 where name = 'ls'; -- Roll back the transaction rollback; -- Committing a transaction or rolling back a transaction will end the transaction
Mode two : Set up MYSQL Auto submit parameters in 【 understand 】
see MYSQL Whether the transaction is automatically committed in
show variables like '%commit%';Set the parameter of automatic submission as OFF
set autocommit = 0; //0:OFF 1:ON
边栏推荐
- Disk structure
- NIO、BIO、AIO
- Unable to use the bean introduced into the jar package
- Dynamic memory management (1)
- Wechat side: what is consistent hash? In what scenario? What problems have been solved?
- Yyds dry goods inventory junit5 learning II: assumptions class
- Common voting governance in Dao
- Docker installs MySQL 8.0. Detailed steps
- ThreadLocal memory leak
- 进程的通信方式
猜你喜欢

The usage difference between isempty and isblank is so different that so many people can't answer it

Docker 安装 Redis-5.0.12,详细步骤

Idea close global search box

Layer 2 and layer 3 forwarding principle based on VLAN

【Mongodb】READ_ME_TO_RECOVER_YOUR_DATA,数据库被恶意删除

揭秘B站,程序员穿女装敲代码,效率更高是真的吗?

O (n) complexity hand tear sorting interview questions | an article will help you understand counting sorting

2022-06-16 工作记录--JS-判断字符串型数字有几位 + 判断数值型数字有几位 + 限制文本长度(最多展示n个字,超出...)

AQS源码分析

Future development of education industry of e-commerce Express
随机推荐
Why can some programmers get good offers with average ability?
Fanuc robot_ Introduction to Karel programming (1)
如何提取网页中的日期?
[QT] QT event handling
重磅!法大大上榜“专精特新”企业
Data communication and physical network
堆內存分配的並發問題
为什么有的程序员能力一般却能拿到好offer?
Web攻击之CSRF和SSRF
Ideal L9, new trend of intelligent cockpit
The core concept of JMM: happens before principle
CDN principle
Creating files, recursively creating directories
Chapter 10 project communication management
Zero code can apply data visualization to enterprise management
STP spanning tree protocol Foundation
Description of software version selection of kt6368a Bluetooth dual-mode transparent chip
How to compare two or more distributions: a summary of methods from visualization to statistical testing
Problèmes de concurrence dans l'allocation de mémoire en tas
How to solve the problem that the computer suddenly can't connect to WiFi