MySQL 死鎖導致無法查詢解決

最近在維護數據庫時,解析數據時候,數據一直不能入庫。原因知道,是因爲MySQL的事務產生了死鎖,前幾次我直接重啓MySQL.
最近發現頻繁的出現。所以找到一種方法。
SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX;
trx_id trx_state trx_started trx_requested_lock_id trx_wait_started trx_weight trx_mysql_thread_id
trx_query trx_operation_state trx_tables_in_use trx_tables_locked trx_lock_structs
trx_lock_memory_bytes
trx_rows_locked trx_rows_modified trx_concurrency_tickets trx_isolation_level trx_unique_checks
trx_foreign_key_checks trx_last_foreign_key_error trx_adaptive_hash_latched
trx_adaptive_hash_timeouttrx_id
trx_state trx_started trx_requested_lock_id trx_wait_started trx_weight trx_mysql_thread_id trx_query
trx_operation_state trx_tables_in_use trx_tables_locked trx_lock_structs trx_lock_memory_bytes
trx_rows_locked trx_rows_modified trx_concurrency_tickets trx_isolation_level trx_unique_checks
trx_foreign_key_checks trx_last_foreign_key_error trx_adaptive_hash_latched trx_adaptive_hash_timeout
查看事件比較久的事物。如何當前時間select sysdate();AM 10:07而事物開始的時間是:AM 9:50,顯示是不正常的。根據這個事物的線程ID(trx_mysql_thread_id)。
執行命令:
kill 線程ID
數據庫修復正常。
查看正在鎖的事務
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;
查看等待鎖的事務
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章