i am using a mysql database version 5. I have a table, that has about 500.000.000 rows.The table reclaims 50GB of diskspace if i trust phpmyadmin. I like to delete 90% of the rows to reclaim disk space.
What is the best option?
-
I can delete the rows using a script and run "OPTIMIZE TABLE". The table will be locked but i dont know how long it can take? Have anybody some experiences?
-
I can drop the table, create a new one and import the 10% manually. How long drop table will take at this size?
Thanks!
2
Answers
Since you want to delete most of the rows in the table, I would recommend moving the rows you want to keep to a temporary table, truncating the table, then re-importing. This still requires downtime on the table (that is, there should be no reads or writes to the table while the operation is in progress), but should be an order of magnitude faster than deleting row by row.
Implictely,
truncate table
drops and recreates the table, which will reclaim the space. The documentation has a few interesting bullet point as regard to your question, such as:the fastest Way is