当前位置:网站首页>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
边栏推荐
- Wx applet jump page
- Applet opening traffic master
- December 6, 2019 what happens after the browser enters a URL
- 傳輸層 以字節為單比特的滑動窗口技術
- VNC viewer remote connection raspberry pie without display
- Dry and wet contacts
- Jar package merging using Apache ant
- Unmanned driving: Some Thoughts on multi-sensor fusion
- Hyperledger Fabric 2. X dynamic update smart contract
- JDBC —— 数据库连接
猜你喜欢
Registration method of native method in JNI
Collective example
Alternative to log4j
Interesting checkbox counters
Use of JMeter
Decoupling pages and components using lifecycle
水库大坝安全监测
Tongji and Ali won the CVPR best student thesis, lifeifei won the Huang xutao award, and nearly 6000 people attended the offline conference
Go crawler framework -colly actual combat (III) -- panoramic cartoon picture capture and download
Ott marketing is booming. How should businesses invest?
随机推荐
Apk decompiled method (not confused)
Im instant messaging development application keeping alive process anti kill
Requests Library
Wallpaper applet wechat applet
Encryption and encoding resolution
Go crawler framework -colly actual combat (II) -- Douban top250 crawling
Human body transformation vs digital Avatar
linux 系统redis常用命令
Design scheme of authority management of fusion model
What are the advantages of VR panoramic production? Why is it favored?
How to quickly open traffic master for wechat applet
JMeter socket connection sends data
How does VR panorama make money? Based on the objective analysis of the market from two aspects
@mysql
Simple collation of Web cache
Eye gaze estimation using webcam
MySQL log management
离散数学及其应用 2018-2019学年春夏学期期末考试 习题详解
2019 summary and 2020 outlook
Fast pace? high pressure? VR panoramic Inn brings you a comfortable life