<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="compiling-for-debugging">
      </a>
      7.9.1.1 Compiling MySQL for Debugging
     </h4>
    </div>
   </div>
  </div>
  <p>
   If you have some very specific problem, you can always try to
        debug MySQL. To do this you must configure MySQL with the
   <a class="link" href="source-configuration-options.html#option_cmake_with_debug">
    <code class="option">
     -DWITH_DEBUG=1
    </code>
   </a>
   option. You can
        check whether MySQL was compiled with debugging by doing:
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld --help
     </strong>
    </span>
   </a>
   . If the
   <a class="link" href="server-options.html#option_mysqld_debug">
    <code class="option">
     --debug
    </code>
   </a>
   flag is listed with the
        options then you have debugging enabled.
   <a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
    <span class="command">
     <strong>
      mysqladmin
        ver
     </strong>
    </span>
   </a>
   also lists the
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   version
        as
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql ... --debug
     </strong>
    </span>
   </a>
   in this case.
  </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>
   stops crashing when you configure
        it with the
   <a class="link" href="source-configuration-options.html#option_cmake_with_debug">
    <code class="option">
     -DWITH_DEBUG=1
    </code>
   </a>
   CMake
        option, you probably have found a compiler bug or a timing bug
        within MySQL. In this case, you can try to add
   <code class="option">
    -g
   </code>
   using the
   <a class="link" href="source-configuration-options.html#option_cmake_cmake_c_flags">
    <code class="option">
     CMAKE_C_FLAGS
    </code>
   </a>
   and
   <a class="link" href="source-configuration-options.html#option_cmake_cmake_cxx_flags">
    <code class="option">
     CMAKE_CXX_FLAGS
    </code>
   </a>
   CMake options and
        not use
   <a class="link" href="source-configuration-options.html#option_cmake_with_debug">
    <code class="option">
     -DWITH_DEBUG=1
    </code>
   </a>
   . If
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   dies, you can at least attach to it
        with
   <span class="command">
    <strong>
     gdb
    </strong>
   </span>
   or use
   <span class="command">
    <strong>
     gdb
    </strong>
   </span>
   on the
        core file to find out what happened.
  </p>
  <p>
   When you configure MySQL for debugging you automatically enable
        a lot of extra safety check functions that monitor the health of
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   . If they find something
   <span class="quote">
    “
    <span class="quote">
     unexpected,
    </span>
    ”
   </span>
   an entry is written to
   <code class="literal">
    stderr
   </code>
   , which
   <a class="link" href="mysqld-safe.html" title="6.3.2 mysqld_safe — MySQL Server Startup Script">
    <span class="command">
     <strong>
      mysqld_safe
     </strong>
    </span>
   </a>
   directs to the error log! This also means that if you are having
        some unexpected problems with MySQL and are using a source
        distribution, the first thing you should do is to configure
        MySQL for debugging. If you believe that you have found a bug,
        please use the instructions at
   <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>
   In the Windows MySQL distribution,
   <code class="literal">
    mysqld.exe
   </code>
   is by default compiled with support for trace files.
  </p>
 </div>
 <br/>
</div>
