Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of MySQL Lock

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "sample analysis of MySQL locks", which is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and study the "sample analysis of MySQL locks".

MySQL locking mechanism

1. MySIAM storage engine

The supported types are table lock, table shared read lock (Table Read Lock), table exclusive write lock (Table Write Lock).

For details, please see this https://www.cnblogs.com/leedaily/p/8378779.html.

Optimistic lock

First, when operating on the database, we think that there must be other operations that will conflict with our changes, so each operation will be locked.

Shared lock (S): SELECT * FROM table_name WHERE... LOCK IN SHARE MODE .

Exclusive lock (X): SELECT * FROM table_name WHERE. FOR UPDATE

Note:

1. The row is locked according to the index, and the table is locked if a non-index field is used.

2. After the row / table is locked, other scripts can read the record normally, but if the record is modified, it will be blocked until the exclusive lock is commit

3. For UPDATE, DELETE, and INSERT statements, InnoDB automatically adds an exclusive lock to the dataset involved (X)

Optimistic lock: think that there will be no data conflicts in the operation, and the database does not support it, so we need to use code logic to implement it. Generally, it is controlled by adding a version field to the database.

1. Add a version field to the table, and each time the data is updated, the value + 1 operation is performed. Then through the previously checked version value, if it is consistent, it will be completed, and an error will be returned if it is inconsistent.

The above is all the content of this article "sample Analysis of MySQL Lock". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report