建站软件 优化软件 编程软件 网页辅助 站群程序 网站程序 图像处理 资源教程 字体下载 推荐软件


您的位置:首页 > MYSQL学习 > 怎么删除mysql大数据

怎么删除mysql大数据

时间:2015-05-07 10:10:18  来源:免费模板网 作者:风雪 阅读次数 tagsmysql运用

我们一般在删除数据的时候  delete然后加上删除条件就可以删除数据,当然简单的可以处理了,遇到不一样的问题那怎么办呢
mysql中删除一般表数据我们会使用delete 或者truncate来清空表数据,但是如果碰到超大表时你会发现此方法有点困难了,下面我以一个mysql删除超大表中的部分数据为示例给各位同学介绍介绍.

mysql普通删除表

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

  1. DELETE [LOW_PRIORITY] [QUICK] [IGNOREFROM tbl_name 
  2.  
  3. [WHERE where_definition] 
  4.  
  5. [ORDER BY ...] 
  6.  
  7. [LIMIT row_count] 

例,代码如下:

  1. delete from friends where user_name = ‘simaopig’; 
  2.  
  3. truncate 语句 TRUNCATE [TABLE] tbl_name 

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

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.phpfensi.com 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,删掉原始表

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

本文地址:https://www.freemoban.com/mysql/2015/0507/1773.html

猜你喜欢
栏目推荐
模板推荐

Copyright:www.freemoban.com 免费模板网 All Rights Reserved 网站备案:辽ICP备19014872号-2   辽公网安备 21010602000376号  辽公网安备:42900402000182号

免责声明:本站部分资源来自互联网收集,版权归原创者所有,如果侵犯了你的权益,我们会及时删除侵权内容,联系QQ:1615187561 谢谢合作!