Created
April 3, 2014 03:00
-
-
Save jdaily/9947545 to your computer and use it in GitHub Desktop.
Empty a mysql table FAST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TRUNCATE is usually a fast operation (much faster than DELETE FROM). But sometimes it just hangs; | |
TRUNCATE on tables with no FOREIGN KEYs should act fast: it translate to dropping the table and creating a new one (and it all depends on the MySQL version, see the manual). | |
Renaming a table (without Foreign Keys) is much faster if its large enough. Instead of: | |
``` | |
TRUNCATE log_table | |
``` | |
Do: | |
``` | |
CREATE TABLE log_table_new LIKE log_table; | |
RENAME TABLE log_table TO log_table_old, log_table_new TO log_table; | |
DROP TABLE log_table_old; | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment