PrefaceI encountered a Mysql deadlock problem some time ago, so I sorted it out. Problem description: Mysql modification statements do not seem to take effect, and an exception will pop up when using the Mysql GUI tool to edit the value of a field. What is deadlock?Before solving the MySQL deadlock problem, let's first understand what a deadlock is. Deadlock refers to a phenomenon in which two or more processes wait for each other due to competition for resources during execution. Without external force, they will not be able to move forward. At this time, the system is said to be in a deadlock state or the system has a deadlock. These processes that are always waiting for each other are called deadlocked processes. Deadlock manifestationThere are two specific manifestations of deadlock: Mysql add and modify statements do not work properly. When you use the Mysql GUI tool to edit the value of a field, an exception occurs. How to avoid deadlock The way to prevent deadlock is to avoid situations where deadlock conditions are met. To this end, we need to follow the following principles during the development process: 1. Try to avoid concurrent execution of statements that involve modifying data. 2. Each transaction is required to lock all the data to be used at one time, otherwise execution is not allowed. 3. A locking order is specified in advance, and all transactions must lock the data in this order. For example, the order in which different processes update objects within a transaction should be kept consistent as much as possible. View DeadlocksThere are many ways to query whether there is a locked table in MySQL. Here we only introduce the most commonly used one. 1. View ongoing transactions SELECT * FROM information_schema.INNODB_TRX You can see that the transaction with process id 3175 is locked, and another transaction with id 3173 is being executed, but has not been committed. 2. View the locked transaction SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS; 3. View transactions waiting for locks SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS; 4. Check whether the table is locked SHOW OPEN TABLES where In_use > 0; When a deadlock occurs, these methods can query information related to the current deadlock. 5. View the log of recent deadlocks show engine innodb status Resolving deadlockIf you need to resolve the deadlock, there is a simple and brutal way, which is to find the process ID and kill it directly. View the processes currently in progress show processlist // You can also use SELECT * FROM information_schema.INNODB_TRX; The process id found by these two commands is the same. Kill the process ID corresponding to the process kill id Verify (check if there is still a lock after killing) SHOW OPEN TABLES where In_use > 0; Reference Links Mysql view table and unlock table What is MySQL deadlock? This is the end of this article about MySQL deadlock checking and deadlock removal. For more information about MySQL deadlock checking and deadlock removal, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of several horizontal and vertical centering methods in HTML (Basics)
>>: Create a movable stack widget function using flutter
1. Demand The local test domain name is the same ...
Preface <br />I have been working in the fro...
Remote connection to MySQL fails, there may be th...
MySQL Advanced SQL Statements use kgc; create tab...
sftp is the abbreviation of Secure File Transfer ...
When using MySQL database, you often encounter su...
This article shares the specific code for JavaScr...
Preface: In the daily use of the database, it is ...
background The interface domain name is not hard-...
Table of contents 1. Download MySQL 2. Install My...
Recently, I have been working on a project and ne...
Table of contents Preface Global Lock Table lock ...
This blog post is about a difficulty encountered ...
This article mainly introduces the process of imp...
Table of contents Ideas Request interception Resp...