mysql kill process解决死锁-
概括:
通过 show processlist; 查看state状态
若发现 有 lock 状态的,则差用以下命令杀死进程
kill id
id为截图中的id,实际为进程id
以上2个语句可在navicat操作界面中执行。
以下为参考文章信息:
1、查看进程列表, 找到ID
show processlist;
+--------+--------+--------------------+----------+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+--------+--------+--------------------+----------+---------+------+----------+------------------+
| 8 | remote | 10.16.30.96:36592 | activity | Sleep | 239 | | NULL |
| 396749 | remote | 172.17.1.122:53028 | activity | Sleep | 1966 | | NULL |
| 397104 | remote | 172.17.3.211:52666 | activity | Sleep | 7 | | NULL |
| 397177 | remote | 172.17.3.211:52819 | activity | Sleep | 7366 | | NULL |
| 397267 | remote | 172.17.1.122:55728 | activity | Sleep | 5741 | | NULL |
| 397268 | remote | 172.17.1.122:55730 | activity | Sleep | 7849 | | NULL |
| 397287 | remote | 172.17.3.150:57151 | activity | Sleep | 7128 | | NULL |
| 397294 | remote | 172.17.3.68:53158 | activity | Sleep | 2882 | | NULL |
| 397296 | remote | 172.17.3.68:53160 | NULL | Sleep | 6492 | | NULL |
2、 查询语句把表锁住了, 赶紧找出第一个Locked的thread_id, 在MySQL的shell里面执行.
kill id
#!/bin/bash
mysql - u root - e " show processlist " | grep - i " Locked " >> locked_log . txt
原文:https://blog.csdn.net/xiaolyuh123/article/details/62044794/
for line in ` cat locked_log.txt | awk '{print $1 }' `
do
echo " kill $line ; " >> kill_thread_id . sql
done
现在kill_thread_id.sql的内容像这个样子
kill 66402982 ;
kill 66402983 ;
kill 66402986 ;
kill 66402991 ;
.....
好了, 我们在mysql的shell中执行, 就可以把所有锁表的进程杀死了.
mysql > source kill_thread_id . sql
当然了, 也可以一行搞定
for id in `mysqladmin processlist | grep -i locked | awk '{print $1}'`
do
mysqladmin kill ${id}
done
;
————————————————
版权声明:本文为CSDN博主「xiaolyuh123」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xiaolyuh123/article/details/62044794/
更多分享,请大家关注我的个人公众号: