当前位置:网站首页>In the process of enterprise development, I found that a colleague used the select * from where condition for update
In the process of enterprise development, I found that a colleague used the select * from where condition for update
2022-06-25 00:23:00 【SteveCode.】
Active address : Graduation season · The technique of attack er
In the workplace Introvert
In the process of enterprise development, I found that a colleague used select * from where Conditions for update
ok ! Today I learned my first hand Send a post by the way . Hey
My article for reference
Novice tutorial -MySQL Business
Interviewer asked :select…for update Will you lock the table or the row ?
Start bar ! Hey
Look at a paragraph sql, Feel if you are confused There may also be big men
BEGIN;
SELECT * FROM a WHERE `key`=1 FOR UPDATE;
UPDATE a SET `name`='songxy9991' WHERE `key` =1;
COMMIT;
SELECT @@autocommit;
SET @@autocommit =0;
SELECT * FROM a WHERE `key`=1 FOR UPDATE;
COMMIT;
UPDATE a SET `name`='songxy12' WHERE `key` =1;
We explain one by one
- Here we are. We'll talk about This transaction Holy and great . Either successful or unsuccessful . Principle 、 Uniformity 、 Isolation, 、 persistence . Wait, Ba , And the isolation level of transactions , also spring Propagation characteristics of transactions in They are all regular interview sites
BEGIN
Is to start a transaction
COMMIT;
Commit transaction
SELECT @@autocommit;
Check whether the transaction is statically auto committed
autocommit State value description
- AUTOCOMMIT=0 Disable auto submit
- AUTOCOMMIT=1 Turn on auto submit
modify state : - SET AUTOCOMMIT=0 Disable auto submit
- SET AUTOCOMMIT=1 Turn on auto submit
MySQL By default, the database will be Automatically start the transaction

Here we are Don't let him commit transactions automatically Stop him first
SET @@autocommit =0;
SELECT @@autocommit;

The real Kung Fu begins Ha
- Create table statement
DROP TABLE IF EXISTS `a`;
CREATE TABLE `a` (
`key` int(0) NOT NULL AUTO_INCREMENT,
`value` char(225) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
PRIMARY KEY (`key`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of a
-- ----------------------------
INSERT INTO `a` VALUES (1, 'ssss', 'songxy12');
INSERT INTO `a` VALUES (2, 'yy', 'songxy');
INSERT INTO `a` VALUES (3, 'sxy', 'songxy');
INSERT INTO `a` VALUES (4, '1111', 'songxy');
INSERT INTO `a` VALUES (5, 'qqq', 'songxy');
SET FOREIGN_KEY_CHECKS = 1;
Let's take a look at the data in my previous table

First, check through the primary key
SELECT * FROM a WHERE `key`=1 FOR UPDATE;
Execute this sql I didn't COMMIT; Ha

In execution
UPDATE a SET `name`='songxy999' WHERE `key` =1;
Look up the table data

- No change
Execute the statement that commits the transaction
COMMIT;

- Is the lock OK or surface Let me try

- Wrong report ;error
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-OPLNv5n5-1655994728162)(https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/4af5d417b96646b0a4a1430460b7d594~tplv-k3u1fbpfcp-watermark.image?)]
Look at the picture

This shows that the lock line
Active address : Graduation season · The technique of attack er
边栏推荐
- Why are life science enterprises on the cloud in succession?
- Encryption and encoding resolution
- Go crawler framework -colly actual combat (IV) -- Zhihu answer crawl (I)
- Helm chart仓库操作
- Modstart: embrace new technologies and take the lead in supporting laravel 9.0
- JPA learning 2 - core annotation, annotation addition, deletion, modification and query, list query result return type, one to many, many to one, many to many
- D manual destruction may violate memory security
- How to use promise Race() and promise any() ?
- JS dynamically generates variable names and assigns values
- 打卡smart精灵#1,品牌不缺吸引力,产品本身实力如何?
猜你喜欢

Decoupling pages and components using lifecycle

Wallpaper applet wechat applet

Meta&伯克利基于池化自注意力机制提出通用多尺度视觉Transformer,在ImageNet分类准确率达88.8%!开源...

Why are life science enterprises on the cloud in succession?

How to delete the entire row with duplicate items in a column of WPS table

The third generation of power electronics semiconductors: SiC MOSFET learning notes (V) research on driving power supply

【面试题】什么是事务,什么是脏读、不可重复读、幻读,以及MySQL的几种事务隔离级别的应对方法
Hyperledger Fabric 2. X dynamic update smart contract

UE4 WebBrowser chart cannot display problems

Unimportant tokens can be stopped in advance! NVIDIA proposes an efficient visual transformer network a-vit with adaptive token to improve the throughput of the model
随机推荐
WordPress add photo album function [advanced custom fields Pro custom fields plug-in series tutorial]
Analysis report on development trend and investment forecast of global and Chinese D-leucine industry from 2022 to 2028
Ten commandments of self-learning in machine learning
The drawableleft of the custom textview in kotlin is displayed in the center together with the text
Is it so difficult to calculate the REM size of the web page according to the design draft?
Scrollview height cannot fill full screen
无人驾驶: 对多传感器融合的一些思考
UE4 WebBrowser图表不能显示问题
C program design topic 15-16 final exam exercise solutions (Part 1)
融合模型权限管理设计方案
Do280openshift access control -- encryption and configmap
The new employee of the Department after 00 is really a champion. He has worked for less than two years. The starting salary of 18K is close to me when he changes to our company
How to quickly open traffic master for wechat applet
Alternative to log4j
Decoupling pages and components using lifecycle
C program design topic 18-19 final exam exercise solutions (Part 2)
Technology sharing | wvp+zlmediakit realizes streaming playback of camera gb28181
Time unified system
MySQL log management
从数字化过渡到智能制造