1205 Lock wait timeout exceeded try restarting transaction

本文详细解析了在MySQL数据库中遇到的死锁问题,通过展示具体案例,包括使用`show processlist`和`show engine innodb status`命令来定位死锁事务,以及介绍如何通过`kill`命令释放被锁定的资源。文章还提供了避免死锁的策略和最佳实践,旨在帮助开发者高效地管理和预防此类问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

早上执行语句:
update report_user_info set cell = replace(cell,'"','') where id<10000;
就报了标题上面的错误。
然后我去查找原因 是因为我早上的一个动作导致 report_user_info表锁住了。
方法1:
mysql -uroot -pmypassword -e"show processlist"|grep -i "locked"
| 103466 | root             | localhost           | report_user        | Killed  | 9646 | query end                   | update report_user_info set cell = replace(cell,'"','')                                              |         0 |      15885184 |  15885185 |
方法2:
show engine innodb status\G
mysql tables in use 1, locked 1
 ROLLING BACK 111427 lock struct(s), heap size 17168824, 16000230 row lock(s), undo log entries 13824412
 MySQL thread id 103466, query id 3367705981 localhost root query end
 update report_user_info set cell = replace(cell,'"','')
 TABLE LOCK table `report_use`.`report_user_info` trx id 8DCD01E4 lock mode IX
 RECORD LOCKS space id 13812 page no 20 n bits 368 index `PRIMARY` of table `report_user`.`report_user_info` trx id 8DCD01E4 lock_mode X
 RECORD LOCKS space id 13812 page no 19027 n bits 360 index `PRIMARY` of table `report_user`.`report_user_info` trx id 8DCD01E4 lock_mode X
 RECORD LOCKS space id 13812 page no 19028 n bits 320 index `PRIMARY` of table `report_user`.`report_user_info` trx id 8DCD01E4 lock_mode X
 RECORD LOCKS space id 13812 page no 19026 n bits 352 index `PRIMARY` of table `report_user`.`report_user_info` trx id 8DCD01E4 lock_mode X
 RECORD LOCKS space id 13812 page no 19030 n bits 248 index `PRIMARY` of table `report_user`.`report_user_info` trx id 8DCD01E4 lock_mode X
 RECORD LOCKS space id 13812 page no 19029 n bits 296 index `PRIMARY` of table `report_user`.`report_user_info` trx id 8DCD01E4 lock_mode X
 RECORD LOCKS space id 13812 page no 19031 n bits 240 index `PRIMARY` of table `report_user`.`report_user_info` trx id 8DCD01E4 lock_mode X
 RECORD LOCKS space id 13812 page no 19031 n bits 368 index `PRIMARY` of table `report_user`.`report_user_info` trx id 8DCD01E4 lock_mode Xlocks gap before rec
 RECORD LOCKS space id 13812 page no 19031 n bits 368 index `PRIMARY` of table `report_user`.`report_user_info` trx id 8DCD01E4 lock_mode X
 TOO MANY LOCKS PRINTED FOR THIS TRX: SUPPRESSING FURTHER PRINTS
 ----------------------------
 END OF INNODB MONITOR OUTPUT
show processlist;
| 103466 | root             | localhost           | report_user        | Locked  | 9646 | query end                   | update report_user_info set cell = replace(cell,'"','')                                              |         0 |      15885184 |  15885185 |
  kill掉这个进程:
mysql>  kill 103466 ;
 Query OK, 0 rows affected (0.00 sec)

当然,可能造成死锁的事务比较的大,他在processlist里面驻留的时间比较的长。

转载:http://blog.youkuaiyun.com/lxpbs8851/article/details/7962435

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值