Mysql出现死锁解决办法

今天使用mysql过程中,突然就卡死了,在客户端执行删除表格操作时,报错:

Deadlock found when trying to get lock

上网查询过后解释说是死锁,也就是表格被锁住了,当时只想着怎么解除这个状态,网上大多都是说怎么修改代码来避免死锁,完全没有提到怎么关闭或者说解除死锁状态,搞得我头昏

最后找到一种方式说是杀掉锁住的进程

在mysql中,输入

mysql> show processlist;
+-------+--------+---------------------+--------+---------+-------+----------+------------------+
| Id    | User   | Host                | db     | Command | Time  | State    | Info             |
+-------+--------+---------------------+--------+---------+-------+----------+------------------+
| 10430 | ng0006 | 192.168.1.160:6     | ng0006 | Sleep   | 11362 |          | NULL             |
| 10431 | ng0006 | 192.168.1.160:6     | ng0006 | Sleep   | 11348 |          | NULL             |
| 12636 | ng0006 | 192.168.1.160:6     | ng0006 | Sleep   | 10907 |          | NULL             |
| 12920 | ng0006 | 192.168.1.160:6     | ng0006 | Sleep   | 10394 |          | NULL             |
| 18459 | ng0006 | 192.168.1.175:6     | NULL   | Sleep   |  6499 |          | NULL             |
| 18460 | ng0006 | 192.168.1.175:6     | ng0006 | Sleep   |  6361 |          | NULL             |
| 18461 | ng0006 | 192.168.1.175:6     | ng0006 | Sleep   |  6493 |          | NULL             |
| 18462 | ng0006 | 192.168.1.175:6     | ng0006 | Sleep   |  6490 |          | NULL             |
| 18463 | ng0006 | 192.168.1.175:6     | ng0006 | Sleep   |  6486 |          | NULL             |    
| 18464 | ng0006 | 192.168.1.175:6     | ng0006 | Sleep   |  6473 |          | NULL             |
| 18465 | ng0006 | 192.168.1.175:6     | ng0006 | Sleep   |  6470 |          | NULL             |
| 18466 | ng0006 | 192.168.1.175:6     | ng0006 | Sleep   |  6459 |          | NULL             |
| 18467 | ng0006 | 192.168.1.175:6     | ng0006 | Sleep   |  6439 |          | NULL             |
| 18468 | ng0006 | 192.168.1.175:6     | ng0006 | Sleep   |  6436 |          | NULL             |
| 18469 | ng0006 | 192.168.1.175:6     | ng0006 | Sleep   |  6429 |          | NULL             |
| 18470 | ng0006 | 192.168.1.175:6     | ng0006 | Sleep   |  6427 |          | NULL             |
| 18471 | ng0006 | 192.168.1.175:6     | ng0006 | Sleep   |  6425 |          | NULL             |    
| 18472 | ng0006 | 192.168.1.175:6     | ng0006 | Sleep   |  6361 |          | NULL             |
| 18483 | ng0006 | ct7cpp:49288        | ng0006 | Query   |     0 | starting | show processlist |
+-------+--------+---------------------+--------+---------+-------+----------+------------------+

kill掉等待中或者睡眠的进程,重复操作即可

mysql> kill 10430;

希望对相同问题的人有帮助

你可能感兴趣的:(Mysql)