MySQL鎖表相關問題查詢思路
預設使用INNODB儲存引擎,查詢當前是否有鎖表情況
select * from information_schema.INNODB_LOCK_WAITS; select * from information_schema.INNODB_LOCKS;
檢視事務等待狀況
SELECT r.trx_id waiting_trx_id, r.trx_mysql_thread_id waiting_thread, r.trx_query waiting_query, b.trx_id blocking_trx_id, b.trx_mysql_thread_id blocking_thread, b.trx_query blocking_query FROM information_schema.innodb_lock_waits w INNER JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id INNER JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id;
檢視更具體的事務等待狀況
SELECT b.trx_state, e.state, e.time, d.state AS block_state, d.time AS block_time, a.requesting_trx_id, a.requested_lock_id, b.trx_query, b.trx_mysql_thread_id, a.blocking_trx_id, a.blocking_lock_id, c.trx_query AS block_trx_query, c.trx_mysql_thread_id AS block_trx_mysql_tread_id FROM information_schema.INNODB_LOCK_WAITS a LEFT JOIN information_schema.INNODB_TRX b ON a.requesting_trx_id = b.trx_id LEFT JOIN information_schema.INNODB_TRX c ON a.blocking_trx_id = c.trx_id LEFT JOIN information_schema.PROCESSLIST d ON c.trx_mysql_thread_id = d.id LEFT JOIN information_schema.PROCESSLIST e ON b.trx_mysql_thread_id = e.id ORDER BY a.requesting_trx_id;
開啟 general log 查詢鎖表事務內語句
SHOW VARIABLES LIKE 'general_log%';
set GLOBAL general_log = on; #開啟 set GLOBAL general_log = off; #關閉 set global log_output='table'; #設定輸出方式為表 -- 根據上述查詢出來的thread_id SELECT * from mysql.general_log WHERE thread_id = 441;
注意:general log會記錄所有的sql語句,除錯過程中,找到自己需要的sql後及時關閉,否則會造出空間不足。
檢視未關閉的事務( MySQL 5.6及以上)
SELECT a.trx_id, a.trx_state, a.trx_started, a.trx_query, b.ID, b.USER, b.DB, b.COMMAND, b.TIME, b.STATE, b.INFO, c.PROCESSLIST_USER, c.PROCESSLIST_HOST, c.PROCESSLIST_DB, d.SQL_TEXT FROM information_schema.INNODB_TRX a LEFT JOIN information_schema.PROCESSLIST b ON a.trx_mysql_thread_id = b.id AND b.COMMAND = 'Sleep' LEFT JOIN PERFORMANCE_SCHEMA.threads c ON b.id = c.PROCESSLIST_ID LEFT JOIN PERFORMANCE_SCHEMA.events_statements_current d ON d.THREAD_ID = c.THREAD_ID;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69903557/viewspace-2749182/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 關於 mysql 中的 rand () 查詢問題MySql
- MySQL死鎖系列-線上死鎖問題排查思路MySql
- mysql鎖表查詢MySql
- MySQL 優化五(關聯查詢子查詢以及 in 的效率問題)(高階篇)MySql優化
- python查詢mysql中文亂碼問題PythonMySql
- 一個MySQL多表查詢的問題MySql
- MySQL中鎖的相關問題DTQUMySql
- 關於mysql查詢字符集不匹配問題的解決方法MySql
- MySQL死鎖問題MySql
- MySQL查詢中分頁思路的優化BFMySql優化
- [20211220]關於標量子查詢問題.txt
- MySQL 相關子查詢MySql
- Mysql中的巢狀子查詢問題QSBSMySql巢狀
- mysql慢查詢,死鎖解決方案MySql
- MySQL 死鎖問題分析MySql
- mysql 5.7.11查詢分割槽表的一個問題MySql
- MySQL函式查詢目錄樹問題記錄MySql函式
- 優化-mysql子查詢索引失效問題解決優化MySql索引
- mysql三表關聯查詢MySql
- mysql 三表關聯查詢MySql
- MySQL 之慢查詢相關操作MySql
- MySQL鎖問題分析-全域性讀鎖MySql
- MySQL鎖等待與死鎖問題分析MySql
- sql 模糊查詢問題SQL
- Mysql運維-資料庫及表相關操作MySql運維資料庫
- Java中關於二分查詢的問題Java
- oracle 查詢鎖 && 解鎖Oracle
- Oracle查詢鎖、解鎖Oracle
- SQL SERVER死鎖查詢,死鎖分析,解鎖,查詢佔用SQLServer
- mysql insert into ... select的鎖問題MySql
- 測試MySQL鎖的問題MySql
- mysql三張表關聯查詢MySql
- mysql中的多表關聯查詢MySql
- mysql帶IN關鍵字的查詢MySql
- leetcode題解(查詢表問題)LeetCode
- JAVA死鎖排查-效能測試問題排查思路Java
- SQL慢查詢排查思路SQL
- 埋點表相關