Home >Database >Mysql Tutorial >What is the difference between mysql table lock and row lock
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.
#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!