虽然截断MySQL中有160万行的表,但它没有显示对truncate
命令的任何响应。
答案 0 :(得分:0)
如果您想要“回复”,可以反复使用此批次。我使用你没有任何索引(索引在where子句上会很好):
DELETE FROM `table`
WHERE (whatever criteria if any)
ORDER BY `id`
LIMIT 1000
我还有另一种阅读方式,但从未尝试过:
for i in `seq 1 1000`; do
mysql -e "select id from table_name where (condition) order by id desc limit 1000 " | sed 's;/|;;g' | awk '{if(NR>1)print "delete from table_name where id = ",$1,";" }' | mysql;
done
如果您仍在寻找更快的方法,请尝试以下方法:
CREATE TABLE new_tbl LIKE tbl;
RENAME TABLE tbl TO old_tbl, new_tbl TO tbl;
DROP TABLE old_tbl;