Using OPTIMIZE TABLE


Finally, we should mention the OPTIMIZE TABLE command. It has the following, very straightforward syntax:

 
 OPTIMIZE TABLE tablename; 

This is the MySQL equivalent of defragmenting your hard disk. As you work with the database, the files that store the data end up with fragments of space within the data where records were deleted or where records had to be moved because an update made them larger. This scattered space is inefficient.

You should use OPTIMIZE TABLE periodically when you have deleted a lot of data from a table or if you have inserted, deleted, or updated a lot of rows and your rows are of variable length. It will tidy up the table's disk storage, re- sort the index, and update statistics for the table.

This command works only on MyISAM and BDB tables at the time of writing.



MySQL Tutorial
MySQL Tutorial
ISBN: 0672325845
EAN: 2147483647
Year: 2003
Pages: 261

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net