OPTIMIZE TABLE tbl_name[, tbl_name, ...]
Much like a hard disk partition becomes fragmented if old files are deleted or resized, MySQL tables become fragmented over time as you delete rows and modify variable-length columns (such as VARCHAR or BLOB). This query performs the database equivalent of a ‘defrag’ on the table, reorganizing the data it contains to eliminate wasted space.
It’s important to note that a table is locked while an optimize operation is going on, so if your application relies on a large table being constantly available, that application will grind to a halt while the optimization takes place. In such cases, it’s better to copy the table, optimize the copy, and then replace the old table with the newly optimized version using a RENAME query. Changes made to the original table in the interim will be lost, so this technique is not appropriate for all applications.