ANALYZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE
    tbl_name [, tbl_name] ...
        ANALYZE TABLE analyzes and stores
        the key distribution for a table. During the analysis, the table
        is locked with a read lock for MyISAM and
        BDB. For InnoDB the table
        is locked with a write lock. This statement works with
        MyISAM, BDB, and (as of
        MySQL 4.0.13) InnoDB tables. For
        MyISAM tables, this statement is equivalent
        to using myisamchk --analyze.
      
        For more information on how the analysis works within
        InnoDB, see
        Section 13.2.15, “Restrictions on InnoDB Tables”.
      
MySQL Enterprise. For expert advice on optimizing tables, subscribe to the MySQL Enterprise Monitor. For more information, see http://www.mysql.com/products/enterprise/advisors.html.
MySQL uses the stored key distribution to decide the order in which tables should be joined when you perform a join on something other than a constant. In addition, key distributions can be used when deciding which indexes to use for a specific table within a query.
        This statement requires SELECT
        and INSERT privileges for the
        table.
      
        ANALYZE TABLE returns a result
        set with the following columns.
      
| Column | Value | 
Table | 
The table name | 
Op | 
Always analyze
 | 
Msg_type | 
status, error,
                info, or warning
 | 
Msg_text | 
An informational message | 
        You can check the stored key distribution with the
        SHOW INDEX statement. See
        Section 12.4.5.13, “SHOW INDEX Syntax”.
      
        If the table has not changed since the last
        ANALYZE TABLE statement, the
        table is not analyzed again.
      
        Before MySQL 4.1.1, ANALYZE TABLE
        statements are not written to the binary log. As of MySQL 4.1.1,
        ANALYZE TABLE statements are
        written to the binary log so that they will be replicated to
        replication slaves. Logging can be suppressed with the optional
        NO_WRITE_TO_BINLOG keyword or its alias
        LOCAL.
      

User Comments
Use mysqlcheck -Aa -uroot -p to run analyze table for all databases and tables (including InnoDB) on a running server. Available in MySQL 3.23.38 and later.
Note that ANALYZE TABLE requires SELECT and INSERT privileges, only (LOCK TABLES is not needed).
Add your own comment.