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死鎖系列-線上死鎖問題排查思路MySql
- 關於 mysql 中的 rand () 查詢問題MySql
- mysql鎖表查詢MySql
- 從trc查詢死鎖的問題
- MySql 鎖表 查詢 命令MySql
- [鎖機制] 鎖相關查詢
- MySQL 優化五(關聯查詢子查詢以及 in 的效率問題)(高階篇)MySql優化
- 求助:DetachedCriteria關聯查詢問題~~
- MySQL 5.7 查詢InnoDB鎖表MySql
- MySQL中鎖的相關問題DTQUMySql
- 一個MySQL多表查詢的問題MySql
- 關於Hibernate的查詢問題
- python查詢mysql中文亂碼問題PythonMySql
- MySQL死鎖問題MySql
- 鎖表的相關資訊查詢
- MySQL查詢中分頁思路的優化BFMySql優化
- 關於mysql查詢字符集不匹配問題的解決方法MySql
- 關於restful 查詢API設計問題RESTAPI
- MySQL 相關子查詢MySql
- MySQL多表關聯查詢MySql
- mysql慢查詢,死鎖解決方案MySql
- 關於分頁查詢的優化思路優化
- Mysql中的巢狀子查詢問題QSBSMySql巢狀
- 轉:Mysql 分割槽 分表相關總結MySql
- 無限級分類---有關查詢問題??
- BIEB:關於CRM系統查詢效能問題
- MySQL 死鎖問題分析MySql
- mysql 三表關聯查詢MySql
- mysql三表關聯查詢MySql
- MySQL 之慢查詢相關操作MySql
- mysql關聯查詢優化MySql優化
- MySQL鎖問題分析-全域性讀鎖MySql
- MySQL鎖等待與死鎖問題分析MySql
- 優化-mysql子查詢索引失效問題解決優化MySql索引
- MySQL函式查詢目錄樹問題記錄MySql函式
- 【原創】查詢原始MySQL死鎖ID薦MySql
- 關於分頁查詢的最佳化思路