In the hundreds of millions of databases, I want to keep the data for the last 10 days and delete the remaining data.

Source: Internet
Author: User
In more than databases, I want to keep the data for the last 10 days and delete the remaining data. Sid | bigint (20) unsigned | NO | PRI | NULL | auto_increment | userid | int (10) unsigned | in 10 million databases, I want to keep data for the last 10 days, delete other data.
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 <= '123 ';
I deleted this piece of data for a long time and did not reflect it. could you tell me how to perform this operation to meet my needs.

------ Solution --------------------
Batch
Mysql> delete from bit_dcsval where insert_datetime <'2017-10-01 'order by insert_datetime limit 2009;
Query OK, 10000 rows affected, 1 warning (3 min 48.40 sec)

The above is an online example
------ Solution --------------------
If 10 million data records only occupy a small portion of the data within 10 days, we recommend that you select this portion into a new table and truncate the original table, then rename the new table to the original table.

If it succeeds, it will take several seconds.

The truncate operation is the most efficient and cannot be recovered.
------ Solution --------------------
What is wrong?

Delete table search;
Rename table search_tmp TO search;

So what?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.