Home  >  Article  >  Database  >  MySQL死锁导致无法查询

MySQL死锁导致无法查询

WBOY
WBOYOriginal
2016-06-07 17:27:151020browse

最近在维护数据库时,解析数据时候,数据一直不能入库。原因知道,是因为MySQL的事务产生了死锁,前几次我直接重启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; 

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn