Answer the question
In order to leave comments, you need to log in
MySQL, deleting 30M records from a table of 40M records
There is a MyISAM log table with 40 million entries, it's time to delete outdated 30 million entries from it.
The table has 5 columns, all indexes.
The request for deletion seemed
DELETE from table where created < date_sub(NOW(), 20 day);
to be running for more than an hour, I interrupted it, during this time only 2 million records were deleted - for a long time ...
Deleting in portions
DELETE from table where id < 1000;
does not seem to give an increase in speed.
What should be done in such cases?
Answer the question
In order to leave comments, you need to log in
ALTER TABLE table DISABLE KEYS;
DELETE from table where created < date_sub(NOW(), 20 day);
ALTER TABLE table ENABLE KEYS;
Try to create a new table and copy 10 million records there, then delete the old one and rename the new one. I support council about DISABLE KEYS.
Faced such a problem. In my case it was the indexes. You can try DISABLE KEYS. For some reason, this function did not turn off all indexes for me.
If it does not work out, then you can simply temporarily demolish all the keys, indexes, etc., delete the records, and then put them again. But at this time it is necessary to prevent the data from being written. This is how I did it, but there is probably a better way.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question