当前位置:网站首页>MySQL transaction
MySQL transaction
2022-06-11 10:03:00 【Don't want to be a programmer】
Business : Either they all succeed 、 Or they all failed ( For example, two people transfer money )
A set of sql Put it in a batch to execute
Business principles :ACID principle
- Atomicity (Atomicity): For the same transaction , Or both , Or it's not done
- Uniformity (Consistency):( Final consistency ) For a transaction, the state before and after the operation is consistent
- Isolation, (Isolation): For multiple users at the same time , It is mainly to exclude the influence of other foods on this affair
- persistence (Durability): The data after the transaction ends will not be lost due to external reasons ( The transaction was not committed , Return to the original state , The transaction has been committed , Persist to database )
The isolation level of the transaction :
- Dirty reading : A transaction reads uncommitted data from another transaction
- Non repeatability : Read a row of data in a table in a transaction , Multiple reads result is different .( This is not necessarily a mistake , It's just that on some occasions it's not right )
- Virtual reading ( Fantasy reading ): It refers to the data inserted by other transactions in a transaction , Leading to inconsistent reading before and after .( It's usually the line effect , One more line )
Perform transactions
– mysql Automatic transaction commit is enabled by default
set autocommit = 0 /* close */
set autocommit = 1 /* Turn on ( default )*/
-- Handle transactions manually
-- The transaction open
start transaction -- Mark the beginning of a transaction , From after sql All in one transaction
insert **
insert **
-- Submit : Persistence ( success !)
commit
-- Roll back : Back to the original ( Failure !)
rollback
-- End of transaction
set autocommit = 1 -- Turn on auto submit
-- understand
savepoint Save point name -- Set a save point for a transaction
rollback to savepoint Save point name -- Roll back to savepoint
release savepoint Save point name -- Undo savepoint
Analog transfer
create database shop character set utf8 collate utf8_general_ci
use shop
create table account
(
id int(3)not null auto_increment ,
name varchar(20) not null,
money decimal(9,2) not null,
primary key (id)
)engine=InnoDB default charset = utf8;
Insert two rows of data 
Simulate transfer transactions
set autocommit = 0; --1 Turn off auto submit
start transaction --2 Start a transaction
update account set money=money-500 where name='ming'--3
update account set money=money+500 where name='hao'--4
commit;--5
rollback;--6
set autocommit = 1;--7
One sentence at a time , In the implementation of the 3、4 After sentence , If direct commit Can not rollback.
边栏推荐
- rac expdp导出时报错:ORA-31693、ORA-31617、ORA-19505
- How much do you know about software compatibility testing? How to select a software compatibility testing organization?
- Introduction to ZigBee module wireless transmission star topology networking structure
- 「INS-30131」 安装程序验证所需的初始设置失败
- parker派克先导式电磁阀和直动式电磁阀的区别有哪些?
- Tap and longtap encapsulation of touch events -- from Ono
- Reconstruction des composants Oracle XDB
- Oracle XDB组件的重建
- 流式计算知识
- Mysql比较
猜你喜欢
随机推荐
CVE-2021-40449 NtGdiResetDC UAF
EMG线性光源发射器有哪些功能和特点呢?
穆格测试控制器的作用和应用场合有哪些
oracle 11g rac 磁盘组有空间无法增加数据文件?
Interface, abstract class and relationship between classes
一万字彻底学会堆和二叉树
帝国CMS仿《手艺活》DIY手工制作网源码/92kaifa仿手艺活自适应手机版模板
What are the ABAP keywords and syntax that cannot be used in the ABAP cloud environment?
Project lifecycle
锐意进取,砥砺前行,JASMINER持续深耕品牌实力
不卷了!入职字节跳动一周就果断跑了。
关于CI框架批量导出至压缩文件
DENISON液压泵用什么液压油?有哪些要求
[Bert]: Calculation of last ave state when training tasks with similar Bert semantics
Q1营收超预期,满帮为何赢得逆风增长?
Ugui picture wall
你对软件兼容性测试知道多少?如何选择软件兼容性测试机构?
等待事件 enq: KO - fast object checkpoint可行的一些处理方法
优秀测试工程师必备的4项安全测试方法!
RAC expdp export error: ora-31693, ora-31617, ora-19505









