当前位置:网站首页>MySQL transactions
MySQL transactions
2022-06-22 07:55:00 【yolo2016】
Mysql Business
summary
A transaction consists of one or more... Of a single unit SQL Sentence composition , In this unit , Every SQL Sentences are interdependent . And the whole single unit as an integral whole , If one of the items in the unit SQL Once the statement fails to execute or produces an error , The entire unit will roll back . All affected data will be returned to the state before the transaction started ; If all of the units SQL Statements are executed successfully , The transaction is executed successfully .
summary : A transaction is a logical set of operations , The units that make up this set of operations , Or all of them will succeed , Or not all of them .
key word : Collection of subtasks , Uniformity , Or success , Or failure
How things work
● After the transaction is opened , All operations are temporarily saved in the transaction log , The transaction log is only available when commit Command will be synchronized to the database , Anything else will clear the transaction log ( rollback , disconnect ).
● MySQL No transaction is opened ( By default ,MySQL Transactions in are automatically committed by default )
● MySQL Manually starting a transaction :
Usage scenarios for transactions
● If you need to execute more than one in a business SQL sentence ( Write ), At this time, transactions are generally required , So as to ensure these multiple SQL Statement execution succeeds or fails at the same time .
● for example : Transfer accounts 、 Batch deletion 、 Submit orders from the shopping cart, etc
The nature of transactions (ACID)
● Atomicity (Atomicity): Atomicity means that a transaction is an indivisible whole , The operations in the transaction are either all successful , All or nothing .
● Uniformity (Consistency): Transactions must cause the database to move from one consistent state to another consistent state . such as : Zhang San has a balance 3000, Li Si has a balance 2000, Zhang San transfers money to Li Si 500, The balance of Zhang San is 2500, The balance of Li Si is 2500, The total balance in the process 5000 It is the same. .
● Isolated type (Isolation): Transaction isolation means that the execution of a transaction cannot be disturbed by other transactions , That is, the operation of a transaction memory and the data used are isolated from other transactions in concurrency , Transactions that execute concurrently cannot interfere with each other .
● persistence (Durability): Persistence means that once a transaction is committed , Its changes to the data in the database are permanent , The following other operations and database failures should not have any impact on it .
The creation of transactions
START TRANSACTION;
command 1,2,3......
......
COMMIT[ROLLBACK];
Transactions are created automatically and manually
SHOW VARIABLES LIKE '%autocommit%';
select @@autocommit;
// 1 Indicates that the transaction is automatically committed 0 Does not automatically submit , need commit or rollback
// mysql The default transaction is auto commit , That is, each execution of sql sentence , Just submit it once .
// Close implicit transactions
SET autocommit = 0;

Isolation level

-- View the isolation level of the current transaction
SELECT @@tx_isolation;
-- Set up current MySQL Isolation level of the connection :
SET TRANSACTION ISOLATION LEVEL [READ UNCOMMITTED|READ COMMITTED|REPEATABLE READ|SERIALIZABLE];
-- Set the global isolation level of the database system :
SET GLOBAL TRANSACTION ISOLATION LEVEL [READ UNCOMMITTED|READ COMMITTED|REPEATABLE READ|SERIALIZABLE];
Reference resources
MySQL Super complete tutorial ,MySQL A complete set of tutorials from getting started to advanced ,B Station must learn mysql Database tutorial
边栏推荐
- 模电实验——实验二 JFET共源极放大电路
- XMIND 2022 mind map active resources?
- 代码覆盖率测试对编程小白的意义及其使用方法
- Asyncstorage quick start
- 【宋红康 MySQL数据库 】【高级篇】【07】MySQL的存储引擎
- Target detection series -- detailed explanation of RCNN principle
- MySQL query group by 1055 is the simplest and most convenient way to solve the problem perfectly
- JS array flattening (recursive writing)
- Open source open source version - pintuan
- [songhongkang MySQL database] [advanced chapter] [06] logical architecture of MySQL
猜你喜欢
随机推荐
Canvastotempfilepath of wechat
mapTalks:基础操作与WMS/WMTS地图服务加载
【宋红康 MySQL数据库 】【高级篇】【06】MySQL的逻辑架构
JS array flattening (recursive writing)
力扣(LeetCode)172. 阶乘后的零(2022.06.21)
lr 2022超详细安装教程「最新」
Xmind 2022思维导图激活版资源?
[songhongkang MySQL database] [advanced chapter] [07] MySQL storage engine
Mystery of power bank
Impact of dead chain on websites
Remote Desktop Manager
Expérience électrique en mode - - expérience 2 circuit d'amplification de source commune JFET
XMIND 2022 mind map active resources?
Get through version - bargain activity
The ranking of websites is very important for websites
ConfigManager JsonToObject
FFMPEG坑
Open version - account information synchronization and unification
网站是否要修改标题
[普通物理]波的能量与干涉






![[普通物理]波的能量与干涉](/img/fe/066aa9e8ed776b8f069b59b7123367.png)


