【问题标题】:how to delete rows in a mysql table having some 1.6 million rows in it如何删除包含大约 160 万行的 mysql 表中的行
【发布时间】:2017-10-17 12:49:45
【问题描述】:

在 MySQL 中截断具有 160 万行的表时,它没有显示对 truncate 命令的任何响应。

【问题讨论】:

  • 您认为什么是“无响应”?你用什么截断?你等了多久?请详细说明您的问题

标签: mysql mysql-python


【解决方案1】:

如果您想要“响应”,您可以重复使用此批次。我正在使用你没有任何索引(索引在 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;

【讨论】:

    猜你喜欢
    • 2023-03-31
    • 2021-08-03
    • 1970-01-01
    • 2010-11-22
    • 1970-01-01
    • 2021-11-14
    • 2015-03-04
    • 1970-01-01
    • 2014-03-18
    相关资源
    最近更新 更多