mysql database delete ten million data operation of the program, will directly delete a long time

  There are a lot on the line a table, has accumulated years of consumption data, the data in this form now need to be cleared away a few years ago, the amount of data of nearly 100 million, the year in which the press data delete, you will find deleted the hours are not returned. This is because each perform a delete, delete the need to record the line as the transaction record keeping for rollback in the log.

   The final adoption of the program are:

    Data (1) to be retained to extract backup table,

    (2) truncate the old table

    (3) data backup table truncate table reinsertion

I perform practical operation as follows:

CREATE TABLE charging_record_old SELECT * FROM charging_record WHERE 1=2;

INSERT INTO charging_record_old SELECT * FROM charging_record cr WHERE cr.recordtime > "2019-01-01 00:01:00";

TABLE charging_record TRUNCATE;
the SET FOREIGN_KEY_CHECKS = 0;
INSERT INTO charging_record the SELECT * the FROM charging_record_old;
actually it only took ten minutes

Talk about here truncate operation: Implicit submit truncate operation can not be rolled back, and not recorded in the log file.

Guess you like

Origin blog.51cto.com/14471175/2433741