博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql删除大表的部分数据
阅读量:7191 次
发布时间:2019-06-29

本文共 1051 字,大约阅读时间需要 3 分钟。

hot3.png

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

今天有人提了一个问题,

一个表有1亿6000万的数据,有一个自增ID。最大值就是1亿6000万,需要删除大于250万以后的数据,有什么办法可以快速删除?
当时看了一眼数据吓尿了,这么大的数据要删除到什么时候啊,最要命的锁表肿么办

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

看到mysql文档有一种解决方案:

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  at all) might be helpful:

  1. 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 ... ;
  2. Use  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;
  3. Drop the original table:

    DROP TABLE t_old;

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

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

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

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

3删掉原始表

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

转载于:https://my.oschina.net/zimingforever/blog/91287

你可能感兴趣的文章
Android + eclipse +ADT安装完全教程
查看>>
BITMAP CONVERSION FROM ROWIDS
查看>>
常见android手机分辨率
查看>>
Inno Setup技巧[实例]添加自定义页面
查看>>
建立与读取.ini文件
查看>>
自己制作QQ空间音乐的具体方法
查看>>
Java:多线程,CyclicBarrier同步器
查看>>
思念是一种美丽的孤独
查看>>
Android中的Interpolator
查看>>
【scrapy】使用方法概要(二)(转)
查看>>
JS 中Promise 模式
查看>>
静态资源的gzip
查看>>
js performance
查看>>
〖Linux〗zigbee实验之cc2430的cc debugger固件升级实录
查看>>
数组前半部分和后半部分有序的全排序
查看>>
动态规划法的一般方法
查看>>
在 Xen 虚拟机下修改系统当前时间
查看>>
Spider Studio 数据挖掘集成开发环境
查看>>
<<.NET B/S 架构实践>> 几种概念区别 - 算法、设计模式、企业应用架构模式、架构模式...
查看>>
SilverLight自定义ImageButton
查看>>