纵有疾风起
人生不言弃

怎么删除mysql大数据

我们一般在删除数据的时候  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,删掉原始表

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

未经允许不得转载:起风网 » 怎么删除mysql大数据
分享到: 生成海报

评论 抢沙发

评论前必须登录!

立即登录