<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="comments">
      </a>
      11.7 Comments
     </h2>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045218248560">
  </a>
  <a class="indexterm" name="idm46045218247488">
  </a>
  <p>
   MySQL Server supports three comment styles:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      From a
      <code class="literal">
       #
      </code>
      character to the end of the line.
     </p>
    </li>
    <li class="listitem">
     <p>
      From a
      <code class="literal">
       --
      </code>
      sequence to the end of the
          line. In MySQL, the
      <code class="literal">
       --
      </code>
      (double-dash)
          comment style requires the second dash to be followed by at
          least one whitespace or control character (such as a space,
          tab, newline, and so on). This syntax differs slightly from
          standard SQL comment syntax, as discussed in
      <a class="xref" href="ansi-diff-comments.html" title="1.7.2.4 '--' as the Start of a Comment">
       Section 1.7.2.4, “'--' as the Start of a Comment”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      From a
      <code class="literal">
       /*
      </code>
      sequence to the following
      <code class="literal">
       */
      </code>
      sequence, as in the C programming
          language. This syntax enables a comment to extend over
          multiple lines because the beginning and closing sequences
          need not be on the same line.
     </p>
    </li>
   </ul>
  </div>
  <p>
   The following example demonstrates all three comment styles:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa74548659"><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-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token number">1</span><span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">;</span>     <span class="token comment" spellcheck="true"># This comment continues to the end of line</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token number">1</span><span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">;</span>     <span class="token comment" spellcheck="true">-- This comment continues to the end of line</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token number">1</span> <span class="token comment" spellcheck="true">/* this is an in-line comment */</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token number">1</span><span class="token operator">+</span>
<span class="token comment" spellcheck="true">/*
this is a
multiple-line comment
*/</span>
<span class="token number">1</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   Nested comments are not supported, and are deprecated; expect them
      to be removed in a future MySQL release. (Under some conditions,
      nested comments might be permitted, but usually are not, and users
      should avoid them.)
  </p>
  <p>
   MySQL Server supports certain variants of C-style comments. These
      enable you to write code that includes MySQL extensions, but is
      still portable, by using comments of the following form:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa93741027"><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-sql"><span class="token comment" spellcheck="true">/*! <em class="replaceable">MySQL-specific code</em> */</span></code></pre>
  </div>
  <p>
   In this case, MySQL Server parses and executes the code within the
      comment as it would any other SQL statement, but other SQL servers
      should ignore the extensions. For example, MySQL Server recognizes
      the
   <code class="literal">
    STRAIGHT_JOIN
   </code>
   keyword in the following
      statement, but other servers should not:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa479381"><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-sql"><span class="token keyword">SELECT</span> <span class="token comment" spellcheck="true">/*! STRAIGHT_JOIN */</span> col1 <span class="token keyword">FROM</span> table1<span class="token punctuation">,</span>table2 <span class="token keyword">WHERE</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
  </div>
  <p>
   If you add a version number after the
   <code class="literal">
    !
   </code>
   character, the syntax within the comment is executed only if the
      MySQL version is greater than or equal to the specified version
      number. The
   <code class="literal">
    KEY_BLOCK_SIZE
   </code>
   keyword in the
      following comment is executed only by servers from MySQL 5.1.10 or
      higher:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa65295402"><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-sql"><span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t1<span class="token punctuation">(</span>a <span class="token datatype">INT</span><span class="token punctuation">,</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment" spellcheck="true">/*!50110 KEY_BLOCK_SIZE=1024 */</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   The version number uses the format
   <em class="replaceable">
    <code>
     Mmmrr
    </code>
   </em>
   , where
   <em class="replaceable">
    <code>
     M
    </code>
   </em>
   is a major version,
   <em class="replaceable">
    <code>
     mm
    </code>
   </em>
   is a two-digit minor version, and
   <em class="replaceable">
    <code>
     rr
    </code>
   </em>
   is a two-digit release number. For
      example: In a statement to be run only by a MySQL server version
      8.4.3 or later, use
   <code class="literal">
    80403
   </code>
   in the comment.
  </p>
  <p>
   In MySQL 8.4, the version number can also optionally
      be comprised of six digits in
   <em class="replaceable">
    <code>
     MMmmrr
    </code>
   </em>
   format, where
   <em class="replaceable">
    <code>
     MM
    </code>
   </em>
   is a two-digit major
      version, and
   <em class="replaceable">
    <code>
     mm
    </code>
   </em>
   and
   <em class="replaceable">
    <code>
     rr
    </code>
   </em>
   are the two-digit minor version and
      two-digit release numbers, respectively.
  </p>
  <p>
   The version number should be followed by at least one whitespace
      character (or the end of the comment). If the comment begins with
      six digits followed by whitespace, this is interpreted as a
      six-digit version number. Otherwise, if it begins with at least
      five digits, these are interpreted as a five-digit version number
      (and any remaining characters ignored for this purpose); if it
      begins with fewer than five digits, the comment is handled as a
      normal MySQL comment.
  </p>
  <p>
   The comment syntax just described applies to how the
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   server parses SQL statements. 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>
   client program also performs some parsing
      of statements before sending them to the server. (It does this to
      determine statement boundaries within a multiple-statement input
      line.) For information about differences between the server and
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   client parsers, see
   <a class="xref" href="mysql-tips.html" title="6.5.1.6 mysql Client Tips">
    Section 6.5.1.6, “mysql Client Tips”
   </a>
   .
  </p>
  <p>
   Comments in
   <code class="literal">
    /*!12345 ... */
   </code>
   format are not
      stored on the server. If this format is used to comment stored
      programs, the comments are not retained in the program body.
  </p>
  <p>
   Another variant of C-style comment syntax is used to specify
      optimizer hints. Hint comments include a
   <code class="literal">
    +
   </code>
   character following the
   <code class="literal">
    /*
   </code>
   comment opening
      sequence. Example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa25263082"><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-sql"><span class="token keyword">SELECT</span> <span class="token comment" spellcheck="true">/*+ BKA(t1) */</span> <span class="token keyword">FROM</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   For more information, see
   <a class="xref" href="optimizer-hints.html" title="10.9.3 Optimizer Hints">
    Section 10.9.3, “Optimizer Hints”
   </a>
   .
  </p>
  <p>
   The use of short-form
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   commands such as
   <code class="literal">
    \C
   </code>
   within multiple-line
   <code class="literal">
    /* ...
      */
   </code>
   comments is not supported. Short-form commands do
      work within single-line
   <code class="literal">
    /*! ... */
   </code>
   version
      comments, as do
   <code class="literal">
    /*+ ... */
   </code>
   optimizer-hint
      comments, which are stored in object definitions. If there is a
      concern that optimizer-hint comments may be stored in object
      definitions so that dump files when reloaded with
   <code class="literal">
    mysql
   </code>
   would result in execution of such
      commands, either invoke
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   with the
   <a class="link" href="mysql-command-options.html#option_mysql_binary-mode">
    <code class="option">
     --binary-mode
    </code>
   </a>
   option or use a reload
      client other than
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   .
  </p>
 </div>
 <br/>
</div>
