Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to empty a very large mysql table?

Whenever I try to empty a large table so using

truncate table the_huge_table;

and wait for several minutes, I see nothing take place. On the other hand I do not want to remove the entire table because not sure how to regenerate it so wondering what is the best way to easily empty this monster?

like image 857
qliq Avatar asked Dec 07 '22 21:12

qliq


1 Answers

SHOW CREATE TABLE the_huge_table will show you how to recreate the table if you drop it.

Another option is to clone the table structure:

CREATE TABLE cloned LIKE the_huge_table;
RENAME TABLE the_huge_table TO drop_me, cloned TO the_huge_table;
DROP TABLE drop_me;
like image 65
Jeff Swensen Avatar answered Dec 19 '22 19:12

Jeff Swensen