mysql interview question 10: What kinds of locks are there in MySQL? What are the differences and connections between table-level locks, row-level locks, and page locks?

Insert image description here

This article focuses on interviews. In interviews, you only need to answer the key points. You do not need to have a very in-depth answer to the framework. If you want to cope with the interview, it is enough. Grasp the key points.

Interviewer: What kinds of locks are there in Mysql?

In MySQL, there are mainly the following types of locks:

  1. Shared Lock: Also known as read lock. Multiple transactions can hold shared locks at the same time and can read but not modify the locked data. Other transactions can also acquire shared locks, but not exclusive locks.

  2. Exclusive Lock: Also known as write lock. After a transaction acquires an exclusive lock, it can read and modify the locked data. Other transactions cannot acquire exclusive locks.

  3. Record Lock: Also known as row lock. When using the InnoDB storage engine, MySQL can lock records in the table to ensure the correctness of concurrent operations. Record locks only take effect on specified records.

  4. Table Lock: Locks the entire table. When using the MyISAM storage engine, MySQL uses table-level locks for concurrency control.

  5. Page Lock: When using the InnoDB storage engine, MySQL will organize multiple adjacent records into one page as needed, and lock this page, which is called a page lock.

  6. Gap Lock: Used to protect the gaps between index ranges to prevent other transactions from inserting new data in the gaps.

Guess you like

Origin blog.csdn.net/qq_27471405/article/details/133442771