Home>Article>Database> What is the difference between mysql table lock and row lock

What is the difference between mysql table lock and row lock

青灯夜游
青灯夜游 Original
2019-05-07 17:11:46 6466browse

Mysql has many such lock mechanisms, such as row locks, table locks, read locks, write locks, etc., which are all locked before operations; these locks are collectively called pessimistic locks (Pessimistic Lock). The following article will take you to understand the locks in MySQL and introduce the difference between table locks and row locks. I hope it will be helpful to you.

What is the difference between mysql table lock and row lock

#Lock is a mechanism for computers to coordinate multiple processes or threads to access a resource concurrently. In a database, in addition to traditional competition for computing resources (such as CPU, RAM, I/O, etc.), data is also a resource shared by many users. How to ensure the consistency and effectiveness of concurrent access to data is a problem that all databases must solve. Lock conflicts are also an important factor affecting the performance of concurrent access to databases. From this perspective, locks are particularly important and complex for databases.

The difference between table locks and row locks in mysql

Row lock

Features: Lock The granularity is small, the probability of lock conflicts is low, and the ability to handle concurrency is strong; the overhead is large, locking is slow, and deadlocks may occur.

Locking method: automatic locking. For UPDATE, DELETE and INSERT statements, InnoDB will automatically add exclusive locks to the involved data sets; for ordinary SELECT statements, InnoDB will not add any locks.

Table lock

Features: low overhead, fast locking, no deadlock; large lock granularity, high probability of lock conflict, low performance under high concurrency

Locking method: automatic locking. Query operations (SELECT) will automatically add read locks to all tables involved, and update operations (UPDATE, DELETE, INSERT) will automatically add write locks to the tables involved.

The above is the detailed content of What is the difference between mysql table lock and row lock. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Can android use mysql? Next article:Can android use mysql?