当前位置:网站首页>MySQL transactions
MySQL transactions
2022-07-19 05:22:00 【HjasnJH】
What is the business ?
Transactions transform a database from one consistency state to another , There is a very simple SQL Sentence composition , It can also be a complex set of SQL Sentence composition ; When the database commits a transaction , You can ensure that either all changes have been saved , Or all changes will not be saved ; Transaction is a program execution unit that accesses and updates various data items in the database .
stay MySQL innodb Next , Every statement is a transaction ; Can pass set autocommit = 0; Set the current session
Move to submit ;
The transaction ACID characteristic
Atomicity (A)
The transaction is either committed , Or roll back
Uniformity (C)
Consistency is defined by the business , Refers to the transition of a transaction from one consistency state to the next , Its business constraints have not been broken , For example, the only key is still the only key .
Isolation, (I)
Transaction isolation refers to the isolation between the execution of transactions and other transactions , adopt MVCC( Multi version concurrency control ) And locks .
persistence (D)
After the transaction is committed , The operation of the transaction will be persisted without loss .
Common transaction statements
-- Show open transactions
START TRANSACTION | BEGIN
-- Commit transaction , And make all changes made to the database persistent
COMMIT
-- Roll back the transaction , End the user's transaction , And undo all pending changes
ROLLBACK
-- Create a savepoint , A transaction can have multiple savepoints
SAVEPOINT identifier
-- Delete a savepoint
RELEASE SAVEPOINT identifier
-- Transaction rolled back to savepoint
ROLLBACK TO [SAVEPOINT] identifierPossible concurrency exceptions of transactions
1、 Dirty reading ( Read uncommitted )
Business (A) You can read another transaction (B) Data not submitted in ; That's business A Read dirty data ;
2、 It can't be read repeatedly ( Read submitted )
Business (A) You can read another transaction (B) Data submitted in ;
3、 Fantasy reading (REPEATABLE READ)
One read operation in a transaction cannot support the following business logic ; It often occurs in a transaction that a read operation is judged and then a write operation is lost
The situation of failure ;
Four levels of isolation
READ UNCOMMITTED
Read uncommitted ; Reads at this level are unlocked , Write and lock , Write locks release locks after a transaction is committed or rolled back
READ COMMITTED
Read submitted ; Support... From this level MVCC ( Multi version concurrency control ), That is, to provide consistent, unlocked reads ; At this time, the read operation reads the historical snapshot data ; At this isolation level, the latest data of the historical version is read , So read the submitted data
READ COMMITTED
Repeatable ; This level also supports MVCC, At this time, the read operation reads the version data at the beginning of the transaction ;
SERIALIZABLE
Serializable ; At this level, a shared lock is added to the read ; So transactions are executed serially ; At this time, the isolation level is the most severe ;
Concurrent exceptions at different isolation levels

边栏推荐
- mysql的缓存方案问题解决
- 新手学习渗透测试的入门指南
- Wechat applet status bar
- Applet cloud development upload pictures to cloud storage
- Easypoi之excel多sheet导入
- Mongo DB aggregate operations and indexes
- Redis 源码分析-数据结构及实现(字典dict)
- RK356x U-Boot研究所(命令篇)3.4 mem内存相关命令的用法
- Three methods for cesium to obtain the longitude and latitude at the mouse click
- es6新增-字符串部分
猜你喜欢

Internship project 3- change owner

Excel imports long data and changes to 000 at the end

Router loopback port experiment

ThreadLocal thread safety example and its principle

Round robin schedule problem

web3js开发技术

用户态协议栈-基于netmap的UDP实现

线上软件测试培训机构柠檬班与iTest.AI平台达成战略合作

分布式注册中心-etcd

Single arm routing configuration
随机推荐
Submit the uniapp form (input, radio, picker) to get the parameter value
(elaborate) ES6 remaining parameters, ES6 built-in objects, template string content (detailed example Dictionary) and practical cases of flexible use of the project
ECS deployment web project
Usage and examples of vlookup function
cookie是否有效时间限定?如何设置cookie?手把手教你设置
2.6.2 memory leakage
遍历的方法总结
redis 源码分析 动态字符串实现(sds)
2.6.2 内存泄漏
Switch user mode, privileged mode, global mode, port mode
Baidu map realizes thermal map
2020-10-22
Use (offset, page) in JS to achieve login effect
指针进阶简单总结
Two JS methods of rolling wheel loading and modal box dragging
MySQL安装配置教程(超级详细)
性能瓶颈查找-火焰图分析
Two methods of obtaining URL parameters and various methods of obtaining location objects
Easypoi excel multi sheet import
Leetcode53. maximum subarray and