从大 table MySql 5.5.46 中删除许多行

Deleting many rows from a big table MySql 5.5.46

以下语句删除重复行并保留最高id

DELETE t1 FROM contacts t1
INNER JOIN contacts t2 
WHERE 
    t1.id < t2.id AND 
    t1.email = t2.email;

此查询两次引用联系人 table,因此,它使用 table 别名 t1 和 t2。

但是我有 600 万行 table,我们需要清理它。

我的第一个方法是用这几行创建一个 SP

REPEAT
DELETE t1 FROM contacts t1
INNER JOIN contacts t2 
WHERE 
    t1.id < t2.id AND 
    t1.email = t2.email
ORDER BY t1.id ASC LIMIT 10000;
UNTIL ROW_COUNT() = 0 END REPEAT;

错误是

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY t1.id ASC LIMIT 10000' at line 17 Time: 0,063s

帮我做一下。

您不能在 DELETE

中的 joined 表中使用 ORDERLIMIT

多重Table语法

DELETE [LOW_PRIORITY] [QUICK] [IGNORE]
    tbl_name[.*] [, tbl_name[.*]] ...
    FROM table_references
    [WHERE where_condition]

DELETE [LOW_PRIORITY] [QUICK] [IGNORE]
    FROM tbl_name[.*] [, tbl_name[.*]] ...
    USING table_references
    [WHERE where_condition]

manual