Get the App
SLTechnology News&Howtos  ›  Database  › 

Introduction of exclusive Lock x and shared Lock s in mysql

Shulou Source: shulou.com Published: 2022-05-31 18:18:12 09月28日 Update

This article mainly introduces "the introduction of exclusive lock x and shared lock s in mysql". In daily operation, I believe that many people have doubts about the introduction of exclusive lock x and shared lock s in mysql. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "introduction of exclusive lock x and shared lock s in mysql". Next, please follow the editor to study!

First of all, the exclusive lock sharing lock must have a premise that the transaction is open.

It all happens in the course of a transaction.

# lock in share mode is required for sharing lock

Select * from table where .lock in share mode

# consistent unlocked read

Select * from table where.

# exclusive lock

Update, insert, delete automatically add exclusive locks

Select * from table_name where .for update

Give an example

Shared lock compatible shared lock

Figure 1

Figure 2

Figure 1 opens the s lock. Figure 2 can also use shared locks. This means that the s lock is a compatible shared lock.

Give an example

Exclusive lock incompatible shared lock exclusive lock

Figure 1. Other locks x locks.

Fig. 2 shared lock s lock is incompatible at this time because there is an x lock in figure 1

Figure 3. Other locks x locks are not compatible.

Conclusion s lock and s lock are compatible with each other. X lock and (x lock, s lock) are not compatible with each other.

At this point, the study on "introduction to exclusive lock x and shared lock s in mysql" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Learning figure 2 transaction more help practical consistent next consistency top row representative premise article method is in state theory knowledge article conclusion Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Technology Xiaomi vpn Shulou Tech Info