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;
精彩评论