Home > Backend Development > PHP Tutorial > 在6千万条数据库里,小弟我要保留最近10天数据,其余数据删除

在6千万条数据库里,小弟我要保留最近10天数据,其余数据删除

WBOY
Release: 2016-06-13 13:41:38
Original
790 people have browsed it

在6千万条数据库里,我要保留最近10天数据,其余数据删除。
sid | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| userid | int(10) unsigned | NO | MUL | 0 | |
| sip | bigint(12) unsigned zerofill | NO | MUL | NULL | |
| stime | int(10) unsigned | NO | MUL | NULL | |
| stype | tinyint(1) unsigned | NO | MUL | NULL | |
| keyword | char(80) | NO | MUL | NULL |  


DELETE FROM search WHERE stime   用这一条数据,我删了很久,都没有反映,请问一下,我该怎么操作一下,实现我的需求。

------解决方案--------------------
分批
mysql> delete from bit_dcsval where insert_datetimeQuery OK, 10000 rows affected, 1 warning (3 min 48.40 sec)

上面是网上的例子
------解决方案--------------------
如果6千万数据中,10天的数据仅仅占一小部分,建议将这部分select into到一张新表里,然后将原来的表truncate掉,之后再将新表rename成原来的表

顺利的话,估计只要几秒钟。

truncate操作是效率最高的,当然也不可恢复。
------解决方案--------------------
出的是什么错?

DELETE TABLE search;
RENAME TABLE search_tmp TO search;

这样呢?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template