Method: 1. Use the "show OPEN TABLES where In_use > 0;" command to check the locked status of the table; 2. Use the "SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS" command to query the locked table.
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
How does mysql query the locked table
1. Check whether the table is locked:
(1) Directly in Mysql command line execution: show engine innodb status\G.
(2) Check the sql statement that caused the deadlock, analyze the index situation, and then optimize the sql.
(3) Then show processlist to check the SQL statements that cause the deadlock to take a long time.
(4)show status like ‘%lock%.
2. Check the table lock status and end deadlock steps:
(1) Check the table lock status: show OPEN TABLES where In_use > 0; This statement records the current lock table status .
(2) Query process: show processlist query table locked process; query the corresponding process killid.
(3) Analyze the SQL that locks the table: analyze the corresponding SQL, add indexes to the table, add indexes to common fields, and add indexes to table related fields.
(4) Check what is being locked: SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS.
(5) View things waiting for locks: SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS.
Extended information
MySQL lock status view command:
Checking table: Checking the data table (this is automatic).
Closing tables: The modified data in the table is being flushed to disk, and the tables that have been used up are being closed. This is a quick operation, but if this is not the case, you should verify that the disk space is full or that the disk is under heavy load.
Connect Out: The replication slave server is connecting to the master server.
Copying to tmp table on disk: Since the temporary result set is larger than tmp_table_size, the temporary table is being converted from memory storage to disk storage to save memory.
Creating tmp table: A temporary table is being created to store some query results.
deleting from main table: The server is performing the first part of a multi-table deletion and has just deleted the first table.
Deleting from reference tables: The server is performing the second part of multi-table deletion and is deleting records from other tables.
Flushing tables: FLUSH TABLES is being executed, waiting for other threads to close the data table.
Killed: If a kill request is sent to a thread, the thread will check the kill flag and give up the next kill request. MySQL will check the kill flag in each main loop, but in some cases the thread may die after a short period of time. If the thread is locked by another thread, the kill request will take effect immediately when the lock is released.
Locked: Locked by other queries.
Sending data: The records of the SELECT query are being processed and the results are being sent to the client.
Sorting for group: Sorting for GROUP BY.
Sorting for order: Sorting for ORDER BY.
Opening tables: This process should be fast unless interfered by other factors. For example, the data table cannot be opened by other threads until the ALTER TABLE or LOCK TABLE statement is executed. Trying to open a table.
Removing duplicates: A SELECT DISTINCT query is being executed, but MySQL cannot optimize out those duplicate records in the previous stage. Therefore, MySQL needs to remove duplicate records again before sending the results to the client.
Reopen table: A lock on a table is obtained, but the lock cannot be obtained until the table structure is modified. The lock has been released, the data table has been closed, and an attempt is made to reopen the data table.
Repair by sorting: The repair directive is sorting to create the index.
Repair with keycache: The repair directive is utilizing the index cache to create new indexes one by one. It will be slower than Repair by sorting.
Searching rows for update: Searching for records that meet the conditions for update. It must be completed before UPDATE is to modify the related records.
Sleeping: Waiting for the client to send a new request.
System lock: Waiting to obtain an external system lock. If you are not currently running multiple mysqld servers requesting the same table at the same time, you can disable external system locks by adding the --skip-external-locking parameter.
Upgrading lock: INSERT DELAYED is trying to obtain a lock table to insert new records.
Updating: Searching for matching records and modifying them. User Lock: Waiting for GET_LOCK().
Waiting for tables: The thread is notified that the data table structure has been modified and the data table needs to be reopened to obtain the new structure. Then, in order to reopen the data table, you must wait until all other threads close the table.
waiting for handler insert: INSERT DELAYED has processed all pending insert operations and is waiting for new requests.
Recommended learning: mysql video tutorial
The above is the detailed content of How to query a locked table in mysql. For more information, please follow other related articles on the PHP Chinese website!

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools
