Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the principle of Mysql lock mechanism?

Shulou Source: shulou.com Published: 2022-06-02 09:43:54 10月04日 Update

This article mainly introduces "what is the principle of Mysql lock mechanism". In daily operation, I believe many people have doubts about what is the principle of Mysql lock mechanism. Xiaobian consulted all kinds of information and sorted out simple and easy operation methods. I hope to help you answer the doubts of "what is the principle of Mysql lock mechanism"! Next, please follow the small series to learn together!

I. Locking mechanisms of different storage engines

Mysql has multiple storage engines, and the locking mechanisms of different storage engines are different;

2. Locking mechanism of InnoDB

InnoDB contains two types of locks: row locks and table locks.

1. When updating data, if there is an index in the where condition, it is a row lock, otherwise it is a table lock;

2. InnoDB row locks have both pessimistic locks and optimistic locks.

Optimistic lock: By default, update sql we write is optimistic lock, that is, only when the update operation is submitted, it will detect whether the version of the row has changed, and update if there is no change (MVCC mechanism).

Pessimal lock: such as select * from table where id = '1001' for update, this is a pessimistic lock, other transactions can not be updated.

At this point, the study of "What is the principle of Mysql lock mechanism" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Tags: Mechanism update principle learning optimism pessimism engine storage different time more help practical next transaction only multiple that is data Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Redmi macOS Shulou Tech Info OPPO Reno