Tuesday, May 13, 2014

Quick way to truncate large tables (GB in size) in MySQL

When using InnoDB engine in MySQL, the truncates can be really slow especially if they have several gigs of data in recordsets

mysql>CREATE TABLE `NEW_TABLE` LIKE `OLD_TABLE`;
mysql>RENAME TABLE `OLD_TABLE` TO `OLD_TABLE_RENAMED`, `NEW_TABLE` TO `OLD_TABLE`;
mysql>DROP TABLE `OLD_TABLE_RENAMED`;

No comments:

Post a Comment