<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="using-log-files">
      </a>
      7.9.1.6 Using Server Logs to Find Causes of Errors in mysqld
     </h4>
    </div>
   </div>
  </div>
  <p>
   Note that before starting
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   with the
        general query log enabled, you should check all your tables with
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   . See
   <a class="xref" href="server-administration.html" title="Chapter 7 MySQL Server Administration">
    Chapter 7,
    <i>
     MySQL Server Administration
    </i>
   </a>
   .
  </p>
  <p>
   If
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   dies or hangs, you should start
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   with the general query log enabled.
        See
   <a class="xref" href="query-log.html" title="7.4.3 The General Query Log">
    Section 7.4.3, “The General Query Log”
   </a>
   . When
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   dies again, you can examine the end of the log file for the
        query that killed
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   .
  </p>
  <p>
   If you use the default general query log file, the log is stored
        in the database directory as
   <code class="filename">
    <em class="replaceable">
     <code>
      host_name
     </code>
    </em>
    .log
   </code>
   In
        most cases it is the last query in the log file that killed
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   , but if possible you should verify
        this by restarting
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   and executing the
        found query from the
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   command-line
        tools. If this works, you should also test all complicated
        queries that did not complete.
  </p>
  <p>
   You can also try the command
   <a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
    <code class="literal">
     EXPLAIN
    </code>
   </a>
   on all
   <a class="link" href="select.html" title="15.2.13 SELECT Statement">
    <code class="literal">
     SELECT
    </code>
   </a>
   statements that takes a
        long time to ensure that
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   is using
        indexes properly. See
   <a class="xref" href="explain.html" title="15.8.2 EXPLAIN Statement">
    Section 15.8.2, “EXPLAIN Statement”
   </a>
   .
  </p>
  <p>
   You can find the queries that take a long time to execute by
        starting
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   with the slow query log
        enabled. See
   <a class="xref" href="slow-query-log.html" title="7.4.5 The Slow Query Log">
    Section 7.4.5, “The Slow Query Log”
   </a>
   .
  </p>
  <p>
   If you find the text
   <code class="literal">
    mysqld restarted
   </code>
   in the
        error log (normally a file named
   <code class="filename">
    <em class="replaceable">
     <code>
      host_name
     </code>
    </em>
    .err
   </code>
   )
        you probably have found a query that causes
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   to fail. If this happens, you should
        check all your tables with
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   (see
   <a class="xref" href="server-administration.html" title="Chapter 7 MySQL Server Administration">
    Chapter 7,
    <i>
     MySQL Server Administration
    </i>
   </a>
   ), and test the queries
        in the MySQL log files to see whether one fails. If you find
        such a query, try first upgrading to the newest MySQL version.
        If this does not help, report a bug, see
   <a class="xref" href="bug-reports.html" title="1.6 How to Report Bugs or Problems">
    Section 1.6, “How to Report Bugs or Problems”
   </a>
   .
  </p>
  <p>
   If you have started
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   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, MySQL automatically checks and tries to repair
   <code class="literal">
    MyISAM
   </code>
   tables if they are marked as 'not
        closed properly' or 'crashed'. If this happens, MySQL writes an
        entry in the
   <code class="literal">
    hostname.err
   </code>
   file
   <code class="literal">
    'Warning: Checking table ...'
   </code>
   which is
        followed by
   <code class="literal">
    Warning: Repairing table
   </code>
   if the
        table needs to be repaired. If you get a lot of these errors,
        without
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   having died unexpectedly just
        before, then something is wrong and needs to be investigated
        further. See
   <a class="xref" href="server-options.html" title="7.1.7 Server Command Options">
    Section 7.1.7, “Server Command Options”
   </a>
   .
  </p>
  <p>
   When the server detects
   <code class="literal">
    MyISAM
   </code>
   table
        corruption, it writes additional information to the error log,
        such as the name and line number of the source file, and the
        list of threads accessing the table. Example:
   <code class="literal">
    Got an
        error from thread_id=1, mi_dynrec.c:368
   </code>
   . This is
        useful information to include in bug reports.
  </p>
  <p>
   It is not a good sign if
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   did die
        unexpectedly, but in this case, you should not investigate the
   <code class="literal">
    Checking table...
   </code>
   messages, but instead try
        to find out why
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   died.
  </p>
 </div>
 <br/>
</div>
