Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use mysql key Lock

Shulou Source: shulou.com Published: 2022-06-03 10:50:56 11月15日 Update

This article shows you the use of mysql key lock, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1. By default, innodb uses key locks to lock records.

Select... For update

2. When the query index contains unique attributes, the key lock will be optimized and degraded to a record lock, that is, only the index itself, not the scope, will be locked.

3. The key lock will degenerate in different scenes.

Example

Transaction 1 start transaction;select SLEEP (4); select * from test where age=22 for update;select * from test where age > 23 for update;select sleep (20); commit; * * transaction 2 start transaction;select sleep (8); select * from test where age=20 for update;select * from test where age=21 for update;select * from test where age=22 for update;select * from test where age=23 for update;commit * * transaction execution status transaction 1 start transaction > OK > time: 0s select SLEEP (4) > OK > time: 4.001s select * from test where age=22 for update > Affected rows: 0 > time: 0.001s select * from test where age > 23 for update > Affected rows: 0 > time: 0.001s select sleep (20) > OK > time: 20s commit > OK > time: 0 .001s * * transaction 2 start transaction > OK > time: 0.001s select sleep (8) > OK > time: 8s select * from test where age=20 for update > Affected rows: 0 > time: 0.001s select * from test where age=21 for update > Affected rows: 0 > time: 0.001s select * from test where age=22 for update > Affected rows: 0 > time: 14.158s select * from test where age=23 for update > Affected rows: 0 > time: 0. 001s commit > OK > time: 0s the above is the use of mysql key lock Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Time transaction method method content skill knowledge index difference conciseness conciseness scenario example namely attribute situation article more state article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Linux MySQL macOS Redmi