MySQL 5.7.25数据库死锁

1、查看innodb状态
show engine innodb status\G

2、开启lock_monitor监控
use databases sys;
create table innodb_lock_monitor(x int) engine=innodb;

3、查询进程
mysql> show processlist;

4、查询死锁事务
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_timeout | trx_is_read_only | trx_autocommit_non_locking |
±--------±----------±--------------------±----------------------±--------------------±-----------±--------------------±---------------------------------------------------------------------±--------------------±------------------±------------------±-----------------±----------------------±----------------±------------------±------------------------±--------------------±------------------±-----------------------±---------------------------±--------------------------±--------------------------±-----------------±---------------------------+
| 2283456 | LOCK WAIT | 2018-12-18 07:38:44 | 2283456:148:3:19 | 2018-12-18 07:38:44 | 2 | 22661 | UPDATE incentecsh.user_wallet SET available = 10 WHERE id = 38 | starting index read | 1 | 1 | 2 | 1136 | 1 | 0 | 0 | REPEATABLE READ | 1 | 1 | NULL | 0 | 0 | 0 | 0 |
| 2278681 | RUNNING | 2018-12-18 06:47:56 | NULL | NULL | 3 | 22374 | NULL | NULL | 0 | 1 | 2 | 1136 | 1 | 1 | 0 | REPEATABLE READ | 1 | 1 | NULL | 0 | 0 | 0 | 0 |
±--------±----------±--------------------±----------------------±--------------------±-----------±--------------------±---------------------------------------------------------------------±--------------------±------------------±------------------±-----------------±----------------------±----------------±------------------±------------------------±--------------------±------------------±-----------------------±---------------------------±--------------------------±--------------------------±-----------------±---------------------------+
2 rows in set (0.01 sec)

5、杀死死锁
kill 22661

备注:
1:查看当前的事务
SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX;

2:查看当前锁定的事务

SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;

3:查看当前等锁的事务
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;

猜你喜欢

转载自blog.csdn.net/inventecsh/article/details/85067409