mysql 查看死锁

mysql 查看死锁

查看正在进行中的事务

MySQL [test]> SELECT * FROM information_schema.INNODB_TRX\G;
*************************** 1. row ***************************
                    trx_id: 3377
                 trx_state: RUNNING
               trx_started: 2022-08-01 09:03:55
     trx_requested_lock_id: NULL
          trx_wait_started: NULL
                trx_weight: 3
       trx_mysql_thread_id: 21
                 trx_query: NULL
       trx_operation_state: NULL
         trx_tables_in_use: 0
         trx_tables_locked: 1
          trx_lock_structs: 2
     trx_lock_memory_bytes: 1128
           trx_rows_locked: 1
         trx_rows_modified: 1
   trx_concurrency_tickets: 0
       trx_isolation_level: REPEATABLE READ
         trx_unique_checks: 1
    trx_foreign_key_checks: 1
trx_last_foreign_key_error: NULL
 trx_adaptive_hash_latched: 0
 trx_adaptive_hash_timeout: 0
          trx_is_read_only: 0
trx_autocommit_non_locking: 0
       trx_schedule_weight: NULL
*************************** 2. row ***************************
                    trx_id: 3376
                 trx_state: LOCK WAIT
               trx_started: 2022-08-01 09:03:48
     trx_requested_lock_id: 139908142630480:3:4:3:139908022887848
          trx_wait_started: 2022-08-01 09:04:02
                trx_weight: 4
       trx_mysql_thread_id: 20
                 trx_query: update t_user set age=12 where id=2
       trx_operation_state: starting index read
         trx_tables_in_use: 1
         trx_tables_locked: 1
          trx_lock_structs: 3
     trx_lock_memory_bytes: 1128
           trx_rows_locked: 2
         trx_rows_modified: 1
   trx_concurrency_tickets: 0
       trx_isolation_level: REPEATABLE READ
         trx_unique_checks: 1
    trx_foreign_key_checks: 1
trx_last_foreign_key_error: NULL
 trx_adaptive_hash_latched: 0
 trx_adaptive_hash_timeout: 0
          trx_is_read_only: 0
trx_autocommit_non_locking: 0
       trx_schedule_weight: 1
2 rows in set (0.00 sec)

查询是否锁表

MySQL [test]> SHOW OPEN TABLES where In_use > 0\G;
*************************** 1. row ***************************
   Database: test
      Table: t_user
     In_use: 1
Name_locked: 0
1 row in set (0.00 sec)

查看最近死锁的日志

MySQL [test]> show engine innodb status\G;
*************************** 1. row ***************************
  Type: InnoDB
  Name: 
Status: 
------------
TRANSACTIONS
------------
Trx id counter 3378
Purge done for trx's n:o < 3376 undo n:o < 0 state: running but idle
History list length 0
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 421383119340328, not started
0 lock struct(s), heap size 1128, 0 row lock(s)
2 lock struct(s), heap size 1128, 1 row lock(s), undo log entries 1
MySQL thread id 21, OS thread handle 139907958769408, query id 467 192.168.226.1 root
---TRANSACTION 3376, ACTIVE 182 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 1128, 4 row lock(s), undo log entries 1
MySQL thread id 20, OS thread handle 139907959826176, query id 479 192.168.226.1 root updating
update t_user set age=12 where id=2
------- TRX HAS BEEN WAITING 17 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 3 page no 4 n bits 72 index PRIMARY of table `test`.`t_user` trx id 3376 lock_mode X locks rec but not gap waiting
Record lock, heap no 3 PHYSICAL RECORD: n_fields 5; compact format; info bits 0
 0: len 8; hex 8000000000000002; asc         ;;
 1: len 6; hex 000000000d31; asc      1;;
 2: len 7; hex 010000011906f8; asc        ;;
 3: len 2; hex 6262; asc bb;;
 4: len 4; hex 8000000e; asc     ;;

可以发现 线程 20和21 被锁住了

看正在执行的sql

MySQL [test]>  show processlist;
+----+-----------------+---------------------+------+---------+--------+------------------------+-------------------------------------+
| Id | User            | Host                | db   | Command | Time   | State                  | Info                                |
+----+-----------------+---------------------+------+---------+--------+------------------------+-------------------------------------+
|  5 | event_scheduler | localhost           | NULL | Daemon  | 231380 | Waiting on empty queue | NULL                                |
| 17 | root            | 172.22.0.1:34568    | test | Query   |      0 | init                   | show processlist                    |
| 18 | root            | 192.168.226.1:50436 | test | Sleep   |   1689 |                        | NULL                                |
| 19 | root            | 192.168.226.1:50437 | test | Sleep   |   1690 |                        | NULL                                |
| 20 | root            | 192.168.226.1:64269 | test | Query   |      9 | updating               | update t_user set age=12 where id=2 |
| 21 | root            | 192.168.226.1:64292 | test | Sleep   |    265 |                        | NULL                                |

kill 线程

MySQL [test]> kill 21;
Query OK, 0 rows affected (0.00 sec)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值