<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="myisam-table-maintenance">
      </a>
      9.6 MyISAM Table Maintenance and Crash Recovery
     </h2>
    </div>
   </div>
  </div>
  <div class="toc">
   <dl class="toc">
    <dt>
     <span class="section">
      <a href="myisam-crash-recovery.html">
       9.6.1 Using myisamchk for Crash Recovery
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="myisam-check.html">
       9.6.2 How to Check MyISAM Tables for Errors
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="myisam-repair.html">
       9.6.3 How to Repair MyISAM Tables
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="myisam-optimization.html">
       9.6.4 MyISAM Table Optimization
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="myisam-maintenance-schedule.html">
       9.6.5 Setting Up a MyISAM Table Maintenance Schedule
      </a>
     </span>
    </dt>
   </dl>
  </div>
  <p>
   This section discusses how to use
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   to
      check or repair
   <code class="literal">
    MyISAM
   </code>
   tables (tables that have
   <code class="filename">
    .MYD
   </code>
   and
   <code class="filename">
    .MYI
   </code>
   files for
      storing data and indexes). For general
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   background, see
   <a class="xref" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    Section 6.6.4, “myisamchk — MyISAM Table-Maintenance Utility”
   </a>
   . Other table-repair information can be
      found at
   <a class="xref" href="rebuilding-tables.html" title="3.14 Rebuilding or Repairing Tables or Indexes">
    Section 3.14, “Rebuilding or Repairing Tables or Indexes”
   </a>
   .
  </p>
  <p>
   You can use
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   to check, repair, or
      optimize database tables. The following sections describe how to
      perform these operations and how to set up a table maintenance
      schedule. For information about using
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   to get information about your tables, see
   <a class="xref" href="myisamchk-table-info.html" title="6.6.4.5 Obtaining Table Information with myisamchk">
    Section 6.6.4.5, “Obtaining Table Information with myisamchk”
   </a>
   .
  </p>
  <p>
   Even though table repair with
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   is
      quite secure, it is always a good idea to make a backup
   <span class="emphasis">
    <em>
     before
    </em>
   </span>
   doing a repair or any maintenance
      operation that could make a lot of changes to a table.
  </p>
  <p>
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   operations that affect indexes can
      cause
   <code class="literal">
    MyISAM
   </code>
   <code class="literal">
    FULLTEXT
   </code>
   indexes to be rebuilt with full-text parameters that are
      incompatible with the values used by the MySQL server. To avoid
      this problem, follow the guidelines in
   <a class="xref" href="myisamchk-general-options.html" title="6.6.4.1 myisamchk General Options">
    Section 6.6.4.1, “myisamchk General Options”
   </a>
   .
  </p>
  <p>
   <code class="literal">
    MyISAM
   </code>
   table maintenance can also be done using
      the SQL statements that perform operations similar to what
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   can do:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      To check
      <code class="literal">
       MyISAM
      </code>
      tables, use
      <a class="link" href="check-table.html" title="15.7.3.2 CHECK TABLE Statement">
       <code class="literal">
        CHECK TABLE
       </code>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      To repair
      <code class="literal">
       MyISAM
      </code>
      tables, use
      <a class="link" href="repair-table.html" title="15.7.3.5 REPAIR TABLE Statement">
       <code class="literal">
        REPAIR TABLE
       </code>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      To optimize
      <code class="literal">
       MyISAM
      </code>
      tables, use
      <a class="link" href="optimize-table.html" title="15.7.3.4 OPTIMIZE TABLE Statement">
       <code class="literal">
        OPTIMIZE TABLE
       </code>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      To analyze
      <code class="literal">
       MyISAM
      </code>
      tables, use
      <a class="link" href="analyze-table.html" title="15.7.3.1 ANALYZE TABLE Statement">
       <code class="literal">
        ANALYZE TABLE
       </code>
      </a>
      .
     </p>
    </li>
   </ul>
  </div>
  <p>
   For additional information about these statements, see
   <a class="xref" href="table-maintenance-statements.html" title="15.7.3 Table Maintenance Statements">
    Section 15.7.3, “Table Maintenance Statements”
   </a>
   .
  </p>
  <p>
   These statements can be used directly or by means of the
   <a class="link" href="mysqlcheck.html" title="6.5.3 mysqlcheck — A Table Maintenance Program">
    <span class="command">
     <strong>
      mysqlcheck
     </strong>
    </span>
   </a>
   client program. One advantage of
      these statements over
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   is that the
      server does all the work. With
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   , you
      must make sure that the server does not use the tables at the same
      time so that there is no unwanted interaction between
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   and the server.
  </p>
 </div>
 <br/>
</div>
