<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="myisam-maintenance-schedule">
      </a>
      9.6.5 Setting Up a MyISAM Table Maintenance Schedule
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045230456128">
  </a>
  <a class="indexterm" name="idm46045230454640">
  </a>
  <p>
   It is a good idea to perform table checks on a regular basis
        rather than waiting for problems to occur. One way to check and
        repair
   <code class="literal">
    MyISAM
   </code>
   tables is with the
   <a class="link" href="check-table.html" title="15.7.3.2 CHECK TABLE Statement">
    <code class="literal">
     CHECK TABLE
    </code>
   </a>
   and
   <a class="link" href="repair-table.html" title="15.7.3.5 REPAIR TABLE Statement">
    <code class="literal">
     REPAIR TABLE
    </code>
   </a>
   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>
   Another way to check tables is 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>
   . For maintenance purposes, you can
        use
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk -s
     </strong>
    </span>
   </a>
   . The
   <code class="option">
    -s
   </code>
   option (short for
   <a class="link" href="myisamchk-general-options.html#option_myisamchk_silent">
    <code class="option">
     --silent
    </code>
   </a>
   )
        causes
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   to run in silent mode,
        printing messages only when errors occur.
  </p>
  <a class="indexterm" name="idm46045230443088">
  </a>
  <p>
   It is also a good idea to enable automatic
   <code class="literal">
    MyISAM
   </code>
   table checking. For example, whenever
        the machine has done a restart in the middle of an update, you
        usually need to check each table that could have been affected
        before it is used further. (These are
   <span class="quote">
    “
    <span class="quote">
     expected crashed
        tables.
    </span>
    ”
   </span>
   ) To cause the server to check
   <code class="literal">
    MyISAM
   </code>
   tables automatically, start it with
        the
   <a class="link" href="server-system-variables.html#sysvar_myisam_recover_options">
    <code class="literal">
     myisam_recover_options
    </code>
   </a>
   system variable set. See
   <a class="xref" href="server-system-variables.html" title="7.1.8 Server System Variables">
    Section 7.1.8, “Server System Variables”
   </a>
   .
  </p>
  <p>
   You should also check your tables regularly during normal system
        operation. For example, you can run a
   <span class="command">
    <strong>
     cron
    </strong>
   </span>
   job to check important tables once a week, using a line like
        this in a
   <code class="filename">
    crontab
   </code>
   file:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-simple"><div class="docs-select-all right" id="sa28209721"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-simple">35 0 <span class="token operator">*</span> <span class="token operator">*</span> 0 <span class="token operator"></span><em class="replaceable"><span class="token operator">/</span>path<span class="token operator">/</span>to<span class="token operator">/</span>myisamchk</em> <span class="token operator">--</span>fast <span class="token operator">--</span>silent <span class="token operator"></span><em class="replaceable"><span class="token operator">/</span>path<span class="token operator">/</span>to<span class="token operator">/</span>datadir</em><span class="token operator">/</span><span class="token operator">*</span><span class="token operator">/</span><span class="token operator">*</span><span class="token punctuation">.</span>MYI</code></pre>
  </div>
  <p>
   This prints out information about crashed tables so that you can
        examine and repair them as necessary.
  </p>
  <p>
   To start with, execute
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk -s
     </strong>
    </span>
   </a>
   each
        night on all tables that have been updated during the last 24
        hours. As you see that problems occur infrequently, you can back
        off the checking frequency to once a week or so.
  </p>
  <a class="indexterm" name="idm46045230431136">
  </a>
  <p>
   Normally, MySQL tables need little maintenance. If you are
        performing many updates to
   <code class="literal">
    MyISAM
   </code>
   tables with
        dynamic-sized rows (tables with
   <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
    <code class="literal">
     VARCHAR
    </code>
   </a>
   ,
   <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
    <code class="literal">
     BLOB
    </code>
   </a>
   , or
   <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
    <code class="literal">
     TEXT
    </code>
   </a>
   columns) or have tables with
        many deleted rows you may want to defragment/reclaim space from
        the tables from time to time. You can do this by using
   <a class="link" href="optimize-table.html" title="15.7.3.4 OPTIMIZE TABLE Statement">
    <code class="literal">
     OPTIMIZE TABLE
    </code>
   </a>
   on the tables in
        question. Alternatively, if you can stop the
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   server for a while, change location
        into the data directory and use this command while the server is
        stopped:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa97580296"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">myisamchk</span> <span class="token property">-r</span> <span class="token property">-s</span> <span class="token property">--sort-index</span> <span class="token constant">--myisam_sort_buffer_size</span><span class="token attr-value"><span class="token punctuation">=</span>16M</span> */*<span class="token punctuation">.</span>MYI</code></pre>
  </div>
 </div>
 <br/>
</div>
