当前位置:网站首页>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
边栏推荐
- Paint rounded rectangle
- Eliminate duplicate dependencies
- Difficult and miscellaneous problems: A Study on the phenomenon of text fuzziness caused by transform
- Eye gaze estimation using webcam
- Do280openshift access control -- encryption and configmap
- Apk slimming compression experience
- VNC viewer remote connection raspberry pie without display
- Uniapp encapsulated incentive advertisement, screen insert advertisement and banner advertisement
- Dry and wet contacts
- Reservoir dam safety monitoring
猜你喜欢

Applet opening traffic master

JDBC - database connection

5G dtu无线通信模块的电力应用

2019 summary and 2020 outlook
![[interview question] what is a transaction? What are dirty reads, unrepeatable reads, phantom reads, and how to deal with several transaction isolation levels of MySQL](/img/95/02a58c9dc97bd8347b43247e38357d.png)
[interview question] what is a transaction? What are dirty reads, unrepeatable reads, phantom reads, and how to deal with several transaction isolation levels of MySQL

Go crawler framework -colly actual combat (III) -- panoramic cartoon picture capture and download

After 5 years of software testing in didi and ByteDance, it's too real

Go crawler framework -colly actual combat (II) -- Douban top250 crawling

Use of navigation and navigationui

iNFTnews | 国内NFT发展仅限于数字藏品吗?
随机推荐
C WinForm maximizes occlusion of the taskbar and full screen display
Ansible及playbook的相关操作
Simple collation of Web cache
Jar package merging using Apache ant
JDBC —— 数据库连接
Outer screen and widescreen wasted? Harmonyos folding screen design specification teaches you to use it
Collective example
vim使用命令
How to quickly open traffic master for wechat applet
Requests Library
Technology sharing | wvp+zlmediakit realizes streaming playback of camera gb28181
How to use promise Race() and promise any() ?
Report on operation pattern and future prospect of global and Chinese propyl isovalerate industry from 2022 to 2028
Ten commandments of self-learning in machine learning
无需显示屏的VNC Viewer远程连接树莓派
Analysis report on development trend and investment forecast of global and Chinese D-leucine industry from 2022 to 2028
MySQL日志管理
部门新来的00后真是卷王,工作没两年,跳槽到我们公司起薪18K都快接近我了
The third generation of power electronics semiconductors: SiC MOSFET learning notes (V) research on driving power supply
Only positive integers can be entered in the text box