开发者

How to empty a very large mysql table?

开发者 https://www.devze.com 2023-03-04 07:29 出处:网络
Whenever I try to empty a large table so using truncate table the_huge_table; and wait for several minutes, I see nothing 开发者_StackOverflowtake place.

Whenever I try to empty a large table so using

truncate table the_huge_table;

and wait for several minutes, I see nothing 开发者_StackOverflowtake 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?


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;


mysqldump --no-data dbname tablename > /tmp/backup.sql
mysql -e 'drop table tablename' dbname
mysql dbname < /tmp/backup.sql


Copy the structure to a new, empty table.
Drop the old table.
Rename the empty copy.

CREATE TABLE copy_huge_table LIKE the_huge_table;
DROP TABLE the_huge_table;
RENAME TABLE copy_huge_table TO the_huge_table;
0

精彩评论

暂无评论...
验证码 换一张
取 消