DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

(mysql.info.gz) OPTIMIZE TABLE

Info Catalog (mysql.info.gz) CHECKSUM TABLE (mysql.info.gz) Table maintenance SQL (mysql.info.gz) REPAIR TABLE
 
 13.5.2.5 `OPTIMIZE TABLE' Syntax
 ................................
 
      OPTIMIZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE TBL_NAME [, TBL_NAME] ...
 
 `OPTIMIZE TABLE' should be used if you have deleted a large part of a
 table or if you have made many changes to a table with variable-length
 rows (tables that have `VARCHAR', `BLOB', or `TEXT' columns).  Deleted
 records are maintained in a linked list and subsequent `INSERT'
 operations reuse old record positions. You can use `OPTIMIZE TABLE' to
 reclaim the unused space and to defragment the data file.
 
 In most setups, you need not run `OPTIMIZE TABLE' at all.  Even if you
 do a lot of updates to variable-length rows, it's not likely that you
 need to do this more than once a week or month and only on certain
 tables.
 
 For the moment, `OPTIMIZE TABLE' works only on `MyISAM', `BDB' and
 `InnoDB' tables. For `BDB' tables, `OPTIMIZE TABLE' is currently mapped
 to `ANALYZE TABLE'. It was also the case for `InnoDB' tables before
 MySQL 4.1.3; starting from this version it is mapped to `ALTER TABLE'.
  `ANALYZE TABLE' ANALYZE TABLE.
 
 You can get `OPTIMIZE TABLE' to work on other table types by starting
 `mysqld' with the `--skip-new' or `--safe-mode' option; in this case,
 `OPTIMIZE TABLE' is just mapped to `ALTER TABLE'.
 
 `OPTIMIZE TABLE' works as follows:
   1. If the table has deleted or split rows, repair the table.
 
   2. If the index pages are not sorted, sort them.
 
   3. If the statistics are not up to date (and the repair couldn't be
      done by sorting the index), update them.
 
 Note that MySQL locks the table during the time `OPTIMIZE TABLE' is
 running.
 
 Before MySQL 4.1.1, `OPTIMIZE TABLE' statements are not written to the
 binary log. As of MySQL 4.1.1, they are written to the binary log
 unless the optional `NO_WRITE_TO_BINLOG' keyword (or its alias `LOCAL')
 is used.
 
Info Catalog (mysql.info.gz) CHECKSUM TABLE (mysql.info.gz) Table maintenance SQL (mysql.info.gz) REPAIR TABLE
automatically generated byinfo2html