mysql快速删除大表数据部分数据_mysql删除大表的部分数据_MySQL

bitsCN.com

mysql删除大表的部分数据

好久没写博客。最近项目要上线。下班时间还得陪着老妈。实在没时间更新。

今天有人提了一个问题,

一个表有1亿6000万的数据,有一个自增ID。最大值就是1亿6000万,需要删除大于250万以后的数据,有什么办法可以快速删除?

当时看了一眼数据吓尿了,这么大的数据要删除到什么时候啊,最要命的锁表肿么办

delete是不行了,加索引也别想。mysql上delete加low_priorty,quick,ignore估计也帮助不大

看到mysql文档有一种解决方案:http://dev.mysql.com/doc/refman/5.0/en/delete.html

If you are deleting many rows from a large table, you may exceed the lock table size for an InnoDB table. To avoid this problem, or simply to minimize the time that the table remains locked, the following strategy (which does not use DELETE at all) might be helpful:

Select the rows not to be deleted into an empty table that has the same structure as the original table:

INSERT INTO t_copy SELECT * FROM t WHERE ... ;

Use RENAME TABLE to atomically move the original table out of the way and rename the copy to the original name:

RENAME TABLE t TO t_old, t_copy TO t;

Drop the original table:

DROP TABLE t_old;

E文不好,简单的翻译下:

删除达标上的多行数据时,innodb会超出lock table size的限制,最小化的减少锁表的时间的方案是:

1选择不需要删除的数据,并把它们存在一张相同结构的空表里

2重命名原始表,并给新表命名为原始表的原始表名

3删掉原始表

总结一下就是,当时删除大表的一部分数据时可以使用 见新表,拷贝数据,删除旧表,重命名的方法。bitsCN.com

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:php中文网

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值