百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>数据库> mysql删除超大表中的部分数据
分享文章到:

mysql删除超大表中的部分数据

发布时间:01/15 来源: 浏览: 关键词:
mysql中删除一般表数据我们会使用delete 或者truncate来清空表数据,但是如果碰到超大表时你会发现此方法有点困难了,下面我以一个mysql删除超大表中的部分数据为示例给各位同学介绍介绍。

mysql普通删除表

delete 语句的定义:

经常和数据库打交道的孩子们,删除数据的时候用的大多都是 delete 语句。现在让我们来看一下 delete语句的定义。


DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name

[WHERE where_definition]

[ORDER BY ...]

[LIMIT row_count]


delete from friends where user_name = ‘simaopig’;

truncate 语句 TRUNCATE [TABLE] tbl_name

这里简单的给出个示例,我想删除 friends 表中所有的记录,111cn.net可以使用如下语句:

truncate table friends;

但在我在删除超大表时发现 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 www.111cn.net 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删掉原始表

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

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有4人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板