删除查询" ERROR 2006(HY000):MySQL服务器已经消失了#34;

时间:2014-05-19 08:32:12

标签: mysql

要点:

我在P - 表中有250个miljon行,在J - 表中有100 000行。我正在尝试删除P - 表中与J - 表缺乏关系的所有行。

预期结果:

每一行缺少关系(约100 000有关系)将从P - 表中删除。

我正在使用的查询:

DELETE P 
FROM P 
LEFT JOIN J ON J.P_id = P.id 
WHERE J.id IS NULL;

我收到的错误:

ERROR 2006 (HY000): MySQL server has gone away

我尝试了什么:

SET innodb_lock_wait_timeout=63000;
SET wait_timeout=63000;

/* ... followed by the query stated above ... */

问题

如何达到预期效果?


修改

其他信息 - 进程列表

所以我猜这个查询仍在运行..

+-----+------+-----------+---------+---------+-------+--------------+------------------------------------------------------------------------------------------------------+
| Id  | User | Host      | db      | Command | Time  | State        | Info                                                                                                 |
+-----+------+-----------+---------+---------+-------+--------------+------------------------------------------------------------------------------------------------------+
| 540 | root | localhost | scraper | Query   | 63298 | Sending data | DELETE Domain_Page FROM Domain_Page LEFT JOIN StructuredData_Joppli ON StructuredData_Joppli.Domain_ |
| 556 | root | localhost | scraper | Query   |     0 | NULL         | show processlist                                                                                     |
+-----+------+-----------+---------+---------+-------+--------------+------------------------------------------------------------------------------------------------------+

3 个答案:

答案 0 :(得分:0)

更改此

 DELETE P
 FROM P

 DELETE 
 FROM P

答案 1 :(得分:0)

如果没有索引关系,请尝试删除较小的部分。

DELETE P 
FROM P 
LEFT JOIN J ON J.P_id = P.id 
WHERE J.id IS NULL LIMIT 10000;

修改

使用子查询怎么样?请先试用一下测试表。

DELETE p FROM p
JOIN 
(SELECT J.P_Id 
 FROM J LEFT JOIN P ON J.P_Id=P.Id 
 WHERE j.Id IS NULL LIMIT 1000
) P2 ON p.Id=P2.P_Id

答案 2 :(得分:0)

delete 
from P left join J ON J.P_id = P.id 
where J.id IS NULL 

如果列不是NULL但只是空白,则需要执行以下操作:

delete 
frome P 
left join J ON J.P_id = P.id 
where J.id=''