当前位置:网站首页>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

边栏推荐
- Applet cloud development upload pictures to cloud storage
- Excel计算本月剩余天数
- Nacos配置管理
- Pat class B 1017: a divided by B
- 分布式注册中心-etcd
- OpenDDS的QoS和自定义QoS(校时TimingQosPolicy)
- redis源码分析 2 迭代器
- es6新增-对象部分
- 使用js中的(offset,page)实现登录效果
- The principle and local storage of the throttle valve of the rotation chart are summarized
猜你喜欢
随机推荐
H5如何获取内网IP和公网IP
Pat class B 1002: write this number
Submit the uniapp form (input, radio, picker) to get the parameter value
【全网首发】一个月后,我们又从 MySQL 双主切换成了主-从
BUUCTF web WarmUp
字幕文件与视频文件对不上的处理方式
(elaborate) ES6 remaining parameters, ES6 built-in objects, template string content (detailed example Dictionary) and practical cases of flexible use of the project
mysql - 索引
The first smart contract program faucet sol
[ES6] explain in detail the common objects and other methods of set and array (full version)
Markdown notes and related shortcut keys of typora
线上软件测试培训机构柠檬班与iTest.AI平台达成战略合作
Two JS methods of rolling wheel loading and modal box dragging
es6新增-let和const (var的缺点&let及const)
LeetCode53. 最大子数组和
Cesium geojson数据的添加与移除
JS native object plus attributes
Baidu map realizes thermal map
Easypoi之excel简单导出
Installation and fast use of Mongo DB stand-alone version









