Issues with locking in MySQL

Issues with locking in MySQL

Lock classification:

From the granularity of data operations:

Table lock: When operating, the entire table will be locked. Row lock: When operating, the current operation row will be locked.

According to the type of data operation:

Read lock (shared lock): Multiple read operations can be performed simultaneously on the same data without affecting each other. Write lock (exclusive lock): It blocks other clients from writing until the current operation is completed.

insert image description here


Row table lock features:

insert image description here


MyISAM table locks:

How to add table lock
MyISAM automatically adds read locks to all tables involved before executing a query statement (SELECT).
INSERT, etc.), the write lock will be automatically added to the table involved. This process does not require user intervention. Therefore, users generally do not need to use LOCK directly.
TABLE command explicitly locks a MyISAM table.

insert image description here

In short, read locks block writes but do not block reads. A write lock will block both reading and writing.

In addition, MyISAM's read-write lock scheduling is write-first, which is why MyISAM is not suitable as a storage engine for write-dominant tables. Because other threads cannot perform any operations after the write lock is obtained, a large number of updates will make it difficult for the query to obtain the lock, resulting in permanent blocking.


InnoDB row locks

Introduction to row locks Row lock features: biased towards the InnoDB storage engine, high overhead, slow locking; deadlock may occur; minimum locking granularity, lowest probability of lock conflict, and highest concurrency.
There are three biggest differences between InnoDB and MyISAM: one is that it supports transactions; two is that it uses row-level locks; and three is that it supports foreign keys.

Transactions:
A transaction is a logical processing unit consisting of a group of SQL statements.

Four major characteristics of transactions (ACID):

insert image description here
insert image description here

insert image description here

This is the end of this article about MySQL lock related issues. For more information about MySQL lock issues, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Analysis of MySQL lock wait and deadlock problems
  • In-depth analysis of MySQL lock blocking
  • Summary of MySQL lock knowledge points

<<:  Detailed explanation of the process of building an MQTT server using Docker

>>:  JavaScript implements cool mouse tailing effects

Recommend

Detailed explanation of the general steps for SQL statement optimization

Preface This article mainly shares with you the g...

Detailed explanation of primary keys and transactions in MySQL

Table of contents 1. Comments on MySQL primary ke...

Detailed explanation of Js class construction and inheritance cases

The definition and inheritance of classes in JS a...

Usage and difference of Js module packaging exports require import

Table of contents 1. Commonjs exports and require...

javascript to switch by clicking on the picture

Clicking to switch pictures is very common in lif...

Detailed explanation of the use of Element el-button button component

1. Background Buttons are very commonly used, and...

Detailed explanation of the difference between JavaScript onclick and click

Table of contents Why is addEventListener needed?...

What hidden attributes in the form can be submitted with the form

The form elements with visibility=hidden and displ...

Complete MySQL Learning Notes

Table of contents MyISAM and InnoDB Reasons for p...

TCP socket SYN queue and Accept queue difference analysis

First we must understand that a TCP socket in the...

Realize super cool water light effect based on canvas

This article example shares with you the specific...

Learn MySQL execution plan

Table of contents 1. Introduction to the Implemen...

Overview and differences between html inline elements and html block-level elements

Block-level element features : •Always occupies a ...