Since a certain system data sheet of the company exceeds 100 million, considering the pressure of the data sheet. So according to a certain point in time the data table is archived. The following operation is to create a new table in the current database to store historical data, and then perform a cleanup operation on the production table. Archived data can be placed on a new database server if possible. (The specific table name and time node can be modified according to your needs)
Archive sql:
Method 1: Copy the table and insert data according to the conditions (this method does not include other indexes except the primary key index)
- CREATE TABLE lime_survey_549656_20151001 as select * from lime_survey_549656 where submitdate < "2015-10-01 00:00:00";
- ALTER TABLE lime_survey_549656_20151001 change id id int primary key auto_increment;
- CREATE TABLE lime_survey_186194_20151001 as select * from lime_survey_186194 where submitdate < "2015-10-01 00:00:00";
- ALTER TABLE lime_survey_186194_20151001 change id id int primary key auto_increment;
- CREATE TABLE lime_survey_279575_20151001 as select * from lime_survey_279575 where submitdate < "2015-10-01 00:00:00";
- ALTER TABLE lime_survey_279575_20151001 change id id int primary key auto_increment;
Method 2: Create an empty table with the same structure and index as the original table
- create table lime_survey_549656_20151001 like lime_survey_549656;
- INSERT INTO lime_survey_549656_20151001 select * from lime_survey_549656 where submitdate < "2015-10-01 00:00:00";
- create table lime_survey_186194_20151001 like lime_survey_186194;
- INSERT INTO lime_survey_186194_20151001 select * from lime_survey_186194 where submitdate < "2015-10-01 00:00:00";
- create table lime_survey_279575_20151001 like lime_survey_279575;
- INSERT INTO lime_survey_279575_20151001 select * from lime_survey_279575 where submitdate < "2015-10-01 00:00:00";
After the data is archived successfully, clean up the data sql:
- delete from lime_survey_549656 where submitdate < "2015-10-0100:00:00";
- delete from lime_survey_186194 where submitdate < "2015-10-0100:00:00";
- delete from lime_survey_279575 where submitdate < "2015-10-0100:00:00";