<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="information-functions">
      </a>
      14.15 Information Functions
     </h2>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045199035648">
  </a>
  <a class="indexterm" name="idm46045199034576">
  </a>
  <div class="table">
   <a name="idm46045199033088">
   </a>
   <p class="title">
    <b>
     Table 14.20 Information Functions
    </b>
   </p>
   <div class="table-contents">
    <table frame="box" rules="all" summary="A reference that lists information functions.">
     <colgroup>
      <col style="width: 28%"/>
      <col style="width: 71%"/>
     </colgroup>
     <thead>
      <tr>
       <th>
        Name
       </th>
       <th>
        Description
       </th>
      </tr>
     </thead>
     <tbody>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_benchmark">
         <code class="literal">
          BENCHMARK()
         </code>
        </a>
       </td>
       <td>
        Repeatedly execute an expression
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_charset">
         <code class="literal">
          CHARSET()
         </code>
        </a>
       </td>
       <td>
        Return the character set of the argument
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_coercibility">
         <code class="literal">
          COERCIBILITY()
         </code>
        </a>
       </td>
       <td>
        Return the collation coercibility value of the string argument
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_collation">
         <code class="literal">
          COLLATION()
         </code>
        </a>
       </td>
       <td>
        Return the collation of the string argument
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_connection-id">
         <code class="literal">
          CONNECTION_ID()
         </code>
        </a>
       </td>
       <td>
        Return the connection ID (thread ID) for the connection
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_current-role">
         <code class="literal">
          CURRENT_ROLE()
         </code>
        </a>
       </td>
       <td>
        Return the current active roles
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_current-user">
         <code class="literal">
          CURRENT_USER()
         </code>
         ,
         <code class="literal">
          CURRENT_USER
         </code>
        </a>
       </td>
       <td>
        The authenticated user name and host name
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_database">
         <code class="literal">
          DATABASE()
         </code>
        </a>
       </td>
       <td>
        Return the default (current) database name
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_found-rows">
         <code class="literal">
          FOUND_ROWS()
         </code>
        </a>
       </td>
       <td>
        For a SELECT with a LIMIT clause, the number of rows that would be
      returned were there no LIMIT clause
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_icu-version">
         <code class="literal">
          ICU_VERSION()
         </code>
        </a>
       </td>
       <td>
        ICU library version
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_last-insert-id">
         <code class="literal">
          LAST_INSERT_ID()
         </code>
        </a>
       </td>
       <td>
        Value of the AUTOINCREMENT column for the last INSERT
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_roles-graphml">
         <code class="literal">
          ROLES_GRAPHML()
         </code>
        </a>
       </td>
       <td>
        Return a GraphML document representing memory role subgraphs
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_row-count">
         <code class="literal">
          ROW_COUNT()
         </code>
        </a>
       </td>
       <td>
        The number of rows updated
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_schema">
         <code class="literal">
          SCHEMA()
         </code>
        </a>
       </td>
       <td>
        Synonym for DATABASE()
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_session-user">
         <code class="literal">
          SESSION_USER()
         </code>
        </a>
       </td>
       <td>
        Synonym for USER()
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_system-user">
         <code class="literal">
          SYSTEM_USER()
         </code>
        </a>
       </td>
       <td>
        Synonym for USER()
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_user">
         <code class="literal">
          USER()
         </code>
        </a>
       </td>
       <td>
        The user name and host name provided by the client
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="information-functions.html#function_version">
         <code class="literal">
          VERSION()
         </code>
        </a>
       </td>
       <td>
        Return a string that indicates the MySQL server version
       </td>
      </tr>
     </tbody>
    </table>
   </div>
   <div class="table-contents">
    <table cellpadding="0" cellspacing="0" style="position: fixed; top: 0px; display: none; left: 401px; width: 739px;">
     <thead>
      <tr>
       <th style="width: 208.719px;">
        Name
       </th>
       <th style="width: 529.281px;">
        Description
       </th>
      </tr>
     </thead>
    </table>
   </div>
  </div>
  <br class="table-break"/>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <a name="function_benchmark">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_benchmark">
       <code class="literal">
        BENCHMARK(
        <em class="replaceable">
         <code>
          count
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198966272">
     </a>
     <p>
      The
      <a class="link" href="information-functions.html#function_benchmark">
       <code class="literal">
        BENCHMARK()
       </code>
      </a>
      function
          executes the expression
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      repeatedly
      <em class="replaceable">
       <code>
        count
       </code>
      </em>
      times. It may be
          used to time how quickly MySQL processes the expression. The
          result value is
      <code class="literal">
       0
      </code>
      , or
      <code class="literal">
       NULL
      </code>
      for inappropriate arguments such as a
      <code class="literal">
       NULL
      </code>
      or negative repeat count.
     </p>
     <p>
      The intended use is from within 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, which reports query execution times:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa94397531"><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 function">BENCHMARK</span><span class="token punctuation">(</span><span class="token number">1000000</span><span class="token punctuation">,</span><span class="token function">AES_ENCRYPT</span><span class="token punctuation">(</span><span class="token string">'hello'</span><span class="token punctuation">,</span><span class="token string">'goodbye'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> BENCHMARK(1000000,AES_ENCRYPT('hello','goodbye')) <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                                                 0 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set (4.74 sec)</span></code></pre>
     </div>
     <p>
      The time reported is elapsed time on the client end, not CPU
          time on the server end. It is advisable to execute
      <a class="link" href="information-functions.html#function_benchmark">
       <code class="literal">
        BENCHMARK()
       </code>
      </a>
      several times, and
          to interpret the result with regard to how heavily loaded the
          server machine is.
     </p>
     <p>
      <a class="link" href="information-functions.html#function_benchmark">
       <code class="literal">
        BENCHMARK()
       </code>
      </a>
      is intended for
          measuring the runtime performance of scalar expressions, which
          has some significant implications for the way that you use it
          and interpret the results:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         Only scalar expressions can be used. Although the
              expression can be a subquery, it must return a single
              column and at most a single row. For example,
         <a class="link" href="information-functions.html#function_benchmark">
          <code class="literal">
           BENCHMARK(10, (SELECT * FROM
              t))
          </code>
         </a>
         fails if the table
         <code class="literal">
          t
         </code>
         has
              more than one column or more than one row.
        </p>
       </li>
       <li class="listitem">
        <p>
         Executing a
         <code class="literal">
          SELECT
          <em class="replaceable">
           <code>
            expr
           </code>
          </em>
         </code>
         statement
         <em class="replaceable">
          <code>
           N
          </code>
         </em>
         times differs from executing
         <code class="literal">
          SELECT BENCHMARK(
          <em class="replaceable">
           <code>
            N
           </code>
          </em>
          ,
          <em class="replaceable">
           <code>
            expr
           </code>
          </em>
          )
         </code>
         in terms of the
              amount of overhead involved. The two have very different
              execution profiles and you should not expect them to take
              the same amount of time. The former involves the parser,
              optimizer, table locking, and runtime evaluation
         <em class="replaceable">
          <code>
           N
          </code>
         </em>
         times each. The latter
              involves only runtime evaluation
         <em class="replaceable">
          <code>
           N
          </code>
         </em>
         times, and all the other
              components just once. Memory structures already allocated
              are reused, and runtime optimizations such as local
              caching of results already evaluated for aggregate
              functions can alter the results. Use of
         <a class="link" href="information-functions.html#function_benchmark">
          <code class="literal">
           BENCHMARK()
          </code>
         </a>
         thus measures
              performance of the runtime component by giving more weight
              to that component and removing the
         <span class="quote">
          “
          <span class="quote">
           noise
          </span>
          ”
         </span>
         introduced by the network, parser, optimizer, and so
              forth.
        </p>
       </li>
      </ul>
     </div>
    </li>
    <li class="listitem">
     <a name="function_charset">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_charset">
       <code class="literal">
        CHARSET(
        <em class="replaceable">
         <code>
          str
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198935440">
     </a>
     <p>
      Returns the character set of the string argument, or
      <code class="literal">
       NULL
      </code>
      if the argument is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa29937350"><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 function">CHARSET</span><span class="token punctuation">(</span><span class="token string">'abc'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'utf8mb3'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">CHARSET</span><span class="token punctuation">(</span><span class="token function">CONVERT</span><span class="token punctuation">(</span><span class="token string">'abc'</span> <span class="token keyword">USING</span> latin1<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'latin1'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">CHARSET</span><span class="token punctuation">(</span><span class="token function">USER</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'utf8mb3'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_coercibility">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_coercibility">
       <code class="literal">
        COERCIBILITY(
        <em class="replaceable">
         <code>
          str
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198922256">
     </a>
     <p>
      Returns the collation coercibility value of the string
          argument.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa84241396"><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 function">COERCIBILITY</span><span class="token punctuation">(</span><span class="token string">'abc'</span> <span class="token keyword">COLLATE</span> utf8mb4_swedish_ci<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">0</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">COERCIBILITY</span><span class="token punctuation">(</span><span class="token function">USER</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">3</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">COERCIBILITY</span><span class="token punctuation">(</span><span class="token string">'abc'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">4</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">COERCIBILITY</span><span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">5</span></code></pre>
     </div>
     <p>
      The return values have the meanings shown in the following
          table. Lower values have higher precedence.
     </p>
     <div class="informaltable">
      <table summary="Collation coercibility return values, the meaning of each value, and an example of each.">
       <colgroup>
        <col style="width: 15%"/>
        <col style="width: 15%"/>
        <col style="width: 70%"/>
       </colgroup>
       <thead>
        <tr>
         <th scope="col">
          Coercibility
         </th>
         <th scope="col">
          Meaning
         </th>
         <th scope="col">
          Example
         </th>
        </tr>
       </thead>
       <tbody>
        <tr>
         <th scope="row">
          <code class="literal">
           0
          </code>
         </th>
         <td>
          Explicit collation
         </td>
         <td>
          Value with
          <code class="literal">
           COLLATE
          </code>
          clause
         </td>
        </tr>
        <tr>
         <th scope="row">
          <code class="literal">
           1
          </code>
         </th>
         <td>
          No collation
         </td>
         <td>
          Concatenation of strings with different collations
         </td>
        </tr>
        <tr>
         <th scope="row">
          <code class="literal">
           2
          </code>
         </th>
         <td>
          Implicit collation
         </td>
         <td>
          Column value, stored routine parameter or local variable
         </td>
        </tr>
        <tr>
         <th scope="row">
          <code class="literal">
           3
          </code>
         </th>
         <td>
          System constant
         </td>
         <td>
          <a class="link" href="information-functions.html#function_user">
           <code class="literal">
            USER()
           </code>
          </a>
          return value
         </td>
        </tr>
        <tr>
         <th scope="row">
          <code class="literal">
           4
          </code>
         </th>
         <td>
          Coercible
         </td>
         <td>
          Literal string
         </td>
        </tr>
        <tr>
         <th scope="row">
          <code class="literal">
           5
          </code>
         </th>
         <td>
          Numeric
         </td>
         <td>
          Numeric or temporal value
         </td>
        </tr>
        <tr>
         <th scope="row">
          <code class="literal">
           6
          </code>
         </th>
         <td>
          Ignorable
         </td>
         <td>
          <code class="literal">
           NULL
          </code>
          or an expression derived from
          <code class="literal">
           NULL
          </code>
         </td>
        </tr>
       </tbody>
      </table>
     </div>
     <p>
      For more information, see
      <a class="xref" href="charset-collation-coercibility.html" title="12.8.4 Collation Coercibility in Expressions">
       Section 12.8.4, “Collation Coercibility in Expressions”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_collation">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_collation">
       <code class="literal">
        COLLATION(
        <em class="replaceable">
         <code>
          str
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198871792">
     </a>
     <p>
      Returns the collation of the string argument.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa58366955"><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 function">COLLATION</span><span class="token punctuation">(</span><span class="token string">'abc'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'utf8mb4_0900_ai_ci'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">COLLATION</span><span class="token punctuation">(</span>_utf8mb4<span class="token string">'abc'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'utf8mb4_0900_ai_ci'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">COLLATION</span><span class="token punctuation">(</span>_latin1<span class="token string">'abc'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'latin1_swedish_ci'</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_connection-id">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_connection-id">
       <code class="literal">
        CONNECTION_ID()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198860336">
     </a>
     <p>
      Returns the connection ID (thread ID) for the connection.
          Every connection has an ID that is unique among the set of
          currently connected clients.
     </p>
     <p>
      The value returned by
      <a class="link" href="information-functions.html#function_connection-id">
       <code class="literal">
        CONNECTION_ID()
       </code>
      </a>
      is the same
          type of value as displayed in the
      <code class="literal">
       ID
      </code>
      column
          of the Information Schema
      <a class="link" href="information-schema-processlist-table.html" title="28.3.23 The INFORMATION_SCHEMA PROCESSLIST Table">
       <code class="literal">
        PROCESSLIST
       </code>
      </a>
      table, the
      <code class="literal">
       Id
      </code>
      column of
      <a class="link" href="show-processlist.html" title="15.7.7.31 SHOW PROCESSLIST Statement">
       <code class="literal">
        SHOW
          PROCESSLIST
       </code>
      </a>
      output, and the
      <code class="literal">
       PROCESSLIST_ID
      </code>
      column of the Performance
          Schema
      <a class="link" href="performance-schema-threads-table.html" title="29.12.22.8 The threads Table">
       <code class="literal">
        threads
       </code>
      </a>
      table.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa57406376"><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 function">CONNECTION_ID</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">23786</span></code></pre>
     </div>
     <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Warning
      </div>
      <p>
       Changing the session value of the
       <a class="link" href="server-system-variables.html#sysvar_pseudo_thread_id">
        <code class="literal">
         pseudo_thread_id
        </code>
       </a>
       system
            variable changes the value returned by the
       <a class="link" href="information-functions.html#function_connection-id">
        <code class="literal">
         CONNECTION_ID()
        </code>
       </a>
       function.
      </p>
     </div>
    </li>
    <li class="listitem">
     <a name="function_current-role">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_current-role">
       <code class="literal">
        CURRENT_ROLE()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198839424">
     </a>
     <p>
      Returns a
      <code class="literal">
       utf8mb3
      </code>
      string containing the
          current active roles for the current session, separated by
          commas, or
      <code class="literal">
       NONE
      </code>
      if there are none. The
          value reflects the setting of the
      <a class="link" href="server-system-variables.html#sysvar_sql_quote_show_create">
       <code class="literal">
        sql_quote_show_create
       </code>
      </a>
      system
          variable.
     </p>
     <p>
      Suppose that an account is granted roles as follows:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa79431747"><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">GRANT</span> <span class="token string">'r1'</span><span class="token punctuation">,</span> <span class="token string">'r2'</span> <span class="token keyword">TO</span> <span class="token string">'u1'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span>
<span class="token keyword">SET</span> <span class="token keyword">DEFAULT</span> <span class="token keyword">ROLE</span> <span class="token keyword">ALL</span> <span class="token keyword">TO</span> <span class="token string">'u1'</span>@<span class="token string">'localhost'</span><span class="token punctuation">;</span></code></pre>
     </div>
     <p>
      In sessions for
      <code class="literal">
       u1
      </code>
      , the initial
      <a class="link" href="information-functions.html#function_current-role">
       <code class="literal">
        CURRENT_ROLE()
       </code>
      </a>
      value names the
          default account roles. Using
      <a class="link" href="set-role.html" title="15.7.1.11 SET ROLE Statement">
       <code class="literal">
        SET
          ROLE
       </code>
      </a>
      changes that:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa25191225"><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 function">CURRENT_ROLE</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> CURRENT_ROLE()    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> `r1`@`%`,`r2`@`%` <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token keyword">ROLE</span> <span class="token string">'r1'</span><span class="token punctuation">;</span> <span class="token keyword">SELECT</span> <span class="token function">CURRENT_ROLE</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> CURRENT_ROLE() <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> `r1`@`%`       <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_current-user">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_current-user">
       <code class="literal">
        CURRENT_USER
       </code>
      </a>
      ,
      <a class="link" href="information-functions.html#function_current-user">
       <code class="literal">
        CURRENT_USER()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198820000">
     </a>
     <p>
      Returns the user name and host name combination for the MySQL
          account that the server used to authenticate the current
          client. This account determines your access privileges. The
          return value is a string in the
      <code class="literal">
       utf8mb3
      </code>
      character set.
     </p>
     <p>
      The value of
      <a class="link" href="information-functions.html#function_current-user">
       <code class="literal">
        CURRENT_USER()
       </code>
      </a>
      can
          differ from the value of
      <a class="link" href="information-functions.html#function_user">
       <code class="literal">
        USER()
       </code>
      </a>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa23916957"><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 function">USER</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'davida@localhost'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> mysql<span class="token punctuation">.</span><span class="token keyword">user</span><span class="token punctuation">;</span>
<span class="token output">ERROR 1044<span class="token punctuation">:</span> Access denied for user ''@'localhost' to
database 'mysql'</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">CURRENT_USER</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'@localhost'</span></code></pre>
     </div>
     <p>
      The example illustrates that although the client specified a
          user name of
      <code class="literal">
       davida
      </code>
      (as indicated by the
          value of the
      <a class="link" href="information-functions.html#function_user">
       <code class="literal">
        USER()
       </code>
      </a>
      function),
          the server authenticated the client using an anonymous user
          account (as seen by the empty user name part of the
      <a class="link" href="information-functions.html#function_current-user">
       <code class="literal">
        CURRENT_USER()
       </code>
      </a>
      value). One way
          this might occur is that there is no account listed in the
          grant tables for
      <code class="literal">
       davida
      </code>
      .
     </p>
     <p>
      Within a stored program or view,
      <a class="link" href="information-functions.html#function_current-user">
       <code class="literal">
        CURRENT_USER()
       </code>
      </a>
      returns the
          account for the user who defined the object (as given by its
      <code class="literal">
       DEFINER
      </code>
      value) unless defined with the
      <code class="literal">
       SQL SECURITY INVOKER
      </code>
      characteristic. In the
          latter case,
      <a class="link" href="information-functions.html#function_current-user">
       <code class="literal">
        CURRENT_USER()
       </code>
      </a>
      returns the object's invoker.
     </p>
     <p>
      Triggers and events have no option to define the
      <code class="literal">
       SQL
          SECURITY
      </code>
      characteristic, so for these objects,
      <a class="link" href="information-functions.html#function_current-user">
       <code class="literal">
        CURRENT_USER()
       </code>
      </a>
      returns the
          account for the user who defined the object. To return the
          invoker, use
      <a class="link" href="information-functions.html#function_user">
       <code class="literal">
        USER()
       </code>
      </a>
      or
      <a class="link" href="information-functions.html#function_session-user">
       <code class="literal">
        SESSION_USER()
       </code>
      </a>
      .
     </p>
     <p>
      The following statements support use of the
      <a class="link" href="information-functions.html#function_current-user">
       <code class="literal">
        CURRENT_USER()
       </code>
      </a>
      function to take
          the place of the name of (and, possibly, a host for) an
          affected user or a definer; in such cases,
      <a class="link" href="information-functions.html#function_current-user">
       <code class="literal">
        CURRENT_USER()
       </code>
      </a>
      is expanded
          where and as needed:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         <a class="link" href="drop-user.html" title="15.7.1.5 DROP USER Statement">
          <code class="literal">
           DROP USER
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="rename-user.html" title="15.7.1.7 RENAME USER Statement">
          <code class="literal">
           RENAME USER
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="grant.html" title="15.7.1.6 GRANT Statement">
          <code class="literal">
           GRANT
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="revoke.html" title="15.7.1.8 REVOKE Statement">
          <code class="literal">
           REVOKE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-function.html" title="15.1.14 CREATE FUNCTION Statement">
          <code class="literal">
           CREATE FUNCTION
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-procedure.html" title="15.1.17 CREATE PROCEDURE and CREATE FUNCTION Statements">
          <code class="literal">
           CREATE PROCEDURE
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-trigger.html" title="15.1.22 CREATE TRIGGER Statement">
          <code class="literal">
           CREATE TRIGGER
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-event.html" title="15.1.13 CREATE EVENT Statement">
          <code class="literal">
           CREATE EVENT
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="create-view.html" title="15.1.23 CREATE VIEW Statement">
          <code class="literal">
           CREATE VIEW
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="alter-event.html" title="15.1.3 ALTER EVENT Statement">
          <code class="literal">
           ALTER EVENT
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="alter-view.html" title="15.1.11 ALTER VIEW Statement">
          <code class="literal">
           ALTER VIEW
          </code>
         </a>
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="set-password.html" title="15.7.1.10 SET PASSWORD Statement">
          <code class="literal">
           SET PASSWORD
          </code>
         </a>
        </p>
       </li>
      </ul>
     </div>
     <p>
      For information about the implications that this expansion of
      <a class="link" href="information-functions.html#function_current-user">
       <code class="literal">
        CURRENT_USER()
       </code>
      </a>
      has for
          replication, see
      <a class="xref" href="replication-features-current-user.html" title="19.5.1.8 Replication of CURRENT_USER()">
       Section 19.5.1.8, “Replication of CURRENT_USER()”
      </a>
      .
     </p>
     <p>
      This function can be used for the default value of a
      <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
       <code class="literal">
        VARCHAR
       </code>
      </a>
      or
      <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
       <code class="literal">
        TEXT
       </code>
      </a>
      column, as shown in the
          following
      <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
       <code class="literal">
        CREATE TABLE
       </code>
      </a>
      statement:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa28418592"><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> t <span class="token punctuation">(</span>c <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">288</span><span class="token punctuation">)</span> <span class="token function">DEFAULT</span> <span class="token punctuation">(</span><span class="token function">CURRENT_USER</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_database">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_database">
       <code class="literal">
        DATABASE()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198755616">
     </a>
     <p>
      Returns the default (current) database name as a string in the
      <code class="literal">
       utf8mb3
      </code>
      character set. If there is no
          default database,
      <a class="link" href="information-functions.html#function_database">
       <code class="literal">
        DATABASE()
       </code>
      </a>
      returns
      <code class="literal">
       NULL
      </code>
      . Within a stored routine, the
          default database is the database that the routine is
          associated with, which is not necessarily the same as the
          database that is the default in the calling context.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa43531241"><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 function">DATABASE</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'test'</span></code></pre>
     </div>
     <p>
      If there is no default database,
      <a class="link" href="information-functions.html#function_database">
       <code class="literal">
        DATABASE()
       </code>
      </a>
      returns
      <code class="literal">
       NULL
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_found-rows">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_found-rows">
       <code class="literal">
        FOUND_ROWS()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198740528">
     </a>
     <a class="indexterm" name="idm46045198739456">
     </a>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       The
       <code class="literal">
        SQL_CALC_FOUND_ROWS
       </code>
       query modifier
            and accompanying
       <a class="link" href="information-functions.html#function_found-rows">
        <code class="literal">
         FOUND_ROWS()
        </code>
       </a>
       function are deprecated; expect them to be removed in a
            future version of MySQL. Execute the query with
       <code class="literal">
        LIMIT
       </code>
       , and then a second query with
       <a class="link" href="aggregate-functions.html#function_count">
        <code class="literal">
         COUNT(*)
        </code>
       </a>
       and without
       <code class="literal">
        LIMIT
       </code>
       to determine whether there are
            additional rows. For example, instead of these queries:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa36717409"><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 keyword">SQL_CALC_FOUND_ROWS</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> <em class="replaceable">tbl_name</em> <span class="token keyword">WHERE</span> id <span class="token operator">&gt;</span> <span class="token number">100</span> <span class="token keyword">LIMIT</span> <span class="token number">10</span><span class="token punctuation">;</span>
<span class="token keyword">SELECT</span> <span class="token function">FOUND_ROWS</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
      </div>
      <p>
       Use these queries instead:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa42086236"><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 operator">*</span> <span class="token keyword">FROM</span> <em class="replaceable">tbl_name</em> <span class="token keyword">WHERE</span> id <span class="token operator">&gt;</span> <span class="token number">100</span> <span class="token keyword">LIMIT</span> <span class="token number">10</span><span class="token punctuation">;</span>
<span class="token keyword">SELECT</span> <span class="token function">COUNT</span><span class="token punctuation">(</span><span class="token operator">*</span><span class="token punctuation">)</span> <span class="token keyword">FROM</span> <em class="replaceable">tbl_name</em> <span class="token keyword">WHERE</span> id <span class="token operator">&gt;</span> <span class="token number">100</span><span class="token punctuation">;</span></code></pre>
      </div>
      <p>
       <a class="link" href="aggregate-functions.html#function_count">
        <code class="literal">
         COUNT(*)
        </code>
       </a>
       is subject to
            certain optimizations.
       <code class="literal">
        SQL_CALC_FOUND_ROWS
       </code>
       causes some
            optimizations to be disabled.
      </p>
     </div>
     <p>
      A
      <a class="link" href="select.html" title="15.2.13 SELECT Statement">
       <code class="literal">
        SELECT
       </code>
      </a>
      statement may include
          a
      <code class="literal">
       LIMIT
      </code>
      clause to restrict the number of
          rows the server returns to the client. In some cases, it is
          desirable to know how many rows the statement would have
          returned without the
      <code class="literal">
       LIMIT
      </code>
      , but without
          running the statement again. To obtain this row count, include
          an
      <code class="literal">
       SQL_CALC_FOUND_ROWS
      </code>
      option in the
      <a class="link" href="select.html" title="15.2.13 SELECT Statement">
       <code class="literal">
        SELECT
       </code>
      </a>
      statement, and then
          invoke
      <a class="link" href="information-functions.html#function_found-rows">
       <code class="literal">
        FOUND_ROWS()
       </code>
      </a>
      afterward:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa18002774"><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 keyword">SQL_CALC_FOUND_ROWS</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> <em class="replaceable">tbl_name</em>
<span class="token prompt">    -&gt;</span> <span class="token keyword">WHERE</span> id <span class="token operator">&gt;</span> <span class="token number">100</span> <span class="token keyword">LIMIT</span> <span class="token number">10</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">FOUND_ROWS</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
     </div>
     <p>
      The second
      <a class="link" href="select.html" title="15.2.13 SELECT Statement">
       <code class="literal">
        SELECT
       </code>
      </a>
      returns a
          number indicating how many rows the first
      <a class="link" href="select.html" title="15.2.13 SELECT Statement">
       <code class="literal">
        SELECT
       </code>
      </a>
      would have returned had
          it been written without the
      <code class="literal">
       LIMIT
      </code>
      clause.
     </p>
     <p>
      In the absence of the
      <code class="literal">
       SQL_CALC_FOUND_ROWS
      </code>
      option in the most recent successful
      <a class="link" href="select.html" title="15.2.13 SELECT Statement">
       <code class="literal">
        SELECT
       </code>
      </a>
      statement,
      <a class="link" href="information-functions.html#function_found-rows">
       <code class="literal">
        FOUND_ROWS()
       </code>
      </a>
      returns the number
          of rows in the result set returned by that statement. If the
          statement includes a
      <code class="literal">
       LIMIT
      </code>
      clause,
      <a class="link" href="information-functions.html#function_found-rows">
       <code class="literal">
        FOUND_ROWS()
       </code>
      </a>
      returns the number
          of rows up to the limit. For example,
      <a class="link" href="information-functions.html#function_found-rows">
       <code class="literal">
        FOUND_ROWS()
       </code>
      </a>
      returns 10 or 60,
          respectively, if the statement includes
      <code class="literal">
       LIMIT
          10
      </code>
      or
      <code class="literal">
       LIMIT 50, 10
      </code>
      .
     </p>
     <p>
      The row count available through
      <a class="link" href="information-functions.html#function_found-rows">
       <code class="literal">
        FOUND_ROWS()
       </code>
      </a>
      is transient and
          not intended to be available past the statement following the
      <code class="literal">
       SELECT SQL_CALC_FOUND_ROWS
      </code>
      statement. If
          you need to refer to the value later, save it:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa4071419"><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 keyword">SQL_CALC_FOUND_ROWS</span> <span class="token operator">*</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>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token variable">@rows</span> <span class="token operator">=</span> <span class="token function">FOUND_ROWS</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
     </div>
     <p>
      If you are using
      <code class="literal">
       SELECT
          SQL_CALC_FOUND_ROWS
      </code>
      , MySQL must calculate how many
          rows are in the full result set. However, this is faster than
          running the query again without
      <code class="literal">
       LIMIT
      </code>
      ,
          because the result set need not be sent to the client.
     </p>
     <p>
      <code class="literal">
       SQL_CALC_FOUND_ROWS
      </code>
      and
      <a class="link" href="information-functions.html#function_found-rows">
       <code class="literal">
        FOUND_ROWS()
       </code>
      </a>
      can be useful in
          situations when you want to restrict the number of rows that a
          query returns, but also determine the number of rows in the
          full result set without running the query again. An example is
          a Web script that presents a paged display containing links to
          the pages that show other sections of a search result. Using
      <a class="link" href="information-functions.html#function_found-rows">
       <code class="literal">
        FOUND_ROWS()
       </code>
      </a>
      enables you to
          determine how many other pages are needed for the rest of the
          result.
     </p>
     <p>
      The use of
      <code class="literal">
       SQL_CALC_FOUND_ROWS
      </code>
      and
      <a class="link" href="information-functions.html#function_found-rows">
       <code class="literal">
        FOUND_ROWS()
       </code>
      </a>
      is more complex
          for
      <a class="link" href="union.html" title="15.2.18 UNION Clause">
       <code class="literal">
        UNION
       </code>
      </a>
      statements than for
          simple
      <a class="link" href="select.html" title="15.2.13 SELECT Statement">
       <code class="literal">
        SELECT
       </code>
      </a>
      statements,
          because
      <code class="literal">
       LIMIT
      </code>
      may occur at multiple places
          in a
      <a class="link" href="union.html" title="15.2.18 UNION Clause">
       <code class="literal">
        UNION
       </code>
      </a>
      . It may be applied
          to individual
      <a class="link" href="select.html" title="15.2.13 SELECT Statement">
       <code class="literal">
        SELECT
       </code>
      </a>
      statements
          in the
      <a class="link" href="union.html" title="15.2.18 UNION Clause">
       <code class="literal">
        UNION
       </code>
      </a>
      , or global to the
      <a class="link" href="union.html" title="15.2.18 UNION Clause">
       <code class="literal">
        UNION
       </code>
      </a>
      result as a whole.
     </p>
     <p>
      The intent of
      <code class="literal">
       SQL_CALC_FOUND_ROWS
      </code>
      for
      <a class="link" href="union.html" title="15.2.18 UNION Clause">
       <code class="literal">
        UNION
       </code>
      </a>
      is that it should return
          the row count that would be returned without a global
      <code class="literal">
       LIMIT
      </code>
      . The conditions for use of
      <code class="literal">
       SQL_CALC_FOUND_ROWS
      </code>
      with
      <a class="link" href="union.html" title="15.2.18 UNION Clause">
       <code class="literal">
        UNION
       </code>
      </a>
      are:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         The
         <code class="literal">
          SQL_CALC_FOUND_ROWS
         </code>
         keyword must
              appear in the first
         <a class="link" href="select.html" title="15.2.13 SELECT Statement">
          <code class="literal">
           SELECT
          </code>
         </a>
         of the
         <a class="link" href="union.html" title="15.2.18 UNION Clause">
          <code class="literal">
           UNION
          </code>
         </a>
         .
        </p>
       </li>
       <li class="listitem">
        <p>
         The value of
         <a class="link" href="information-functions.html#function_found-rows">
          <code class="literal">
           FOUND_ROWS()
          </code>
         </a>
         is exact only if
         <a class="link" href="union.html" title="15.2.18 UNION Clause">
          <code class="literal">
           UNION ALL
          </code>
         </a>
         is used. If
         <a class="link" href="union.html" title="15.2.18 UNION Clause">
          <code class="literal">
           UNION
          </code>
         </a>
         without
         <code class="literal">
          ALL
         </code>
         is used, duplicate removal occurs
              and the value of
         <a class="link" href="information-functions.html#function_found-rows">
          <code class="literal">
           FOUND_ROWS()
          </code>
         </a>
         is only
              approximate.
        </p>
       </li>
       <li class="listitem">
        <p>
         If no
         <code class="literal">
          LIMIT
         </code>
         is present in the
         <a class="link" href="union.html" title="15.2.18 UNION Clause">
          <code class="literal">
           UNION
          </code>
         </a>
         ,
         <code class="literal">
          SQL_CALC_FOUND_ROWS
         </code>
         is ignored and
              returns the number of rows in the temporary table that is
              created to process the
         <a class="link" href="union.html" title="15.2.18 UNION Clause">
          <code class="literal">
           UNION
          </code>
         </a>
         .
        </p>
       </li>
      </ul>
     </div>
     <p>
      Beyond the cases described here, the behavior of
      <a class="link" href="information-functions.html#function_found-rows">
       <code class="literal">
        FOUND_ROWS()
       </code>
      </a>
      is undefined (for
          example, its value following a
      <a class="link" href="select.html" title="15.2.13 SELECT Statement">
       <code class="literal">
        SELECT
       </code>
      </a>
      statement that fails
          with an error).
     </p>
     <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Important
      </div>
      <p>
       <a class="link" href="information-functions.html#function_found-rows">
        <code class="literal">
         FOUND_ROWS()
        </code>
       </a>
       is not
            replicated reliably using statement-based replication. This
            function is automatically replicated using row-based
            replication.
      </p>
     </div>
    </li>
    <li class="listitem">
     <a name="function_icu-version">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_icu-version">
       <code class="literal">
        ICU_VERSION()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198649760">
     </a>
     <p>
      The version of the International Components for Unicode (ICU)
          library used to support regular expression operations (see
      <a class="xref" href="regexp.html" title="14.8.2 Regular Expressions">
       Section 14.8.2, “Regular Expressions”
      </a>
      ). This function is primarily intended
          for use in test cases.
     </p>
    </li>
    <li class="listitem">
     <a name="function_last-insert-id">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      ,
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID(
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198640784">
     </a>
     <p>
      With no argument,
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      returns a
      <code class="literal">
       BIGINT UNSIGNED
      </code>
      (64-bit) value representing
          the first automatically generated value successfully inserted
          for an
      <code class="literal">
       AUTO_INCREMENT
      </code>
      column as a result of
          the most recently executed
      <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
       <code class="literal">
        INSERT
       </code>
      </a>
      statement. The value of
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      remains
          unchanged if no rows are successfully inserted.
     </p>
     <p>
      With an argument,
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      returns an
          unsigned integer, or
      <code class="literal">
       NULL
      </code>
      if the argument
          is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      For example, after inserting a row that generates an
      <code class="literal">
       AUTO_INCREMENT
      </code>
      value, you can get the value
          like this:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa32441872"><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 function">LAST_INSERT_ID</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">195</span></code></pre>
     </div>
     <p>
      The currently executing statement does not affect the value of
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      . Suppose that
          you generate an
      <code class="literal">
       AUTO_INCREMENT
      </code>
      value with
          one statement, and then refer to
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      in a
          multiple-row
      <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
       <code class="literal">
        INSERT
       </code>
      </a>
      statement
          that inserts rows into a table with its own
      <code class="literal">
       AUTO_INCREMENT
      </code>
      column. The value of
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      remains stable
          in the second statement; its value for the second and later
          rows is not affected by the earlier row insertions. (You
          should be aware that, if you mix references to
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      and
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID(
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        )
       </code>
      </a>
      ,
          the effect is undefined.)
     </p>
     <p>
      If the previous statement returned an error, the value of
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      is undefined.
          For transactional tables, if the statement is rolled back due
          to an error, the value of
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      is left
          undefined. For manual
      <a class="link" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements">
       <code class="literal">
        ROLLBACK
       </code>
      </a>
      ,
          the value of
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      is not restored to that before the transaction; it remains as
          it was at the point of the
      <a class="link" href="commit.html" title="15.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements">
       <code class="literal">
        ROLLBACK
       </code>
      </a>
      .
     </p>
     <p>
      Within the body of a stored routine (procedure or function) or
          a trigger, the value of
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      changes the
          same way as for statements executed outside the body of these
          kinds of objects. The effect of a stored routine or trigger
          upon the value of
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      that is seen
          by following statements depends on the kind of routine:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         If a stored procedure executes statements that change the
              value of
         <a class="link" href="information-functions.html#function_last-insert-id">
          <code class="literal">
           LAST_INSERT_ID()
          </code>
         </a>
         ,
              the changed value is seen by statements that follow the
              procedure call.
        </p>
       </li>
       <li class="listitem">
        <p>
         For stored functions and triggers that change the value,
              the value is restored when the function or trigger ends,
              so statements coming after it do not see a changed value.
        </p>
       </li>
      </ul>
     </div>
     <p>
      The ID that was generated is maintained in the server on a
      <span class="emphasis">
       <em>
        per-connection basis
       </em>
      </span>
      . This means that the
          value returned by the function to a given client is the first
      <code class="literal">
       AUTO_INCREMENT
      </code>
      value generated for most
          recent statement affecting an
      <code class="literal">
       AUTO_INCREMENT
      </code>
      column
      <span class="emphasis">
       <em>
        by that
          client
       </em>
      </span>
      . This value cannot be affected by other
          clients, even if they generate
      <code class="literal">
       AUTO_INCREMENT
      </code>
      values of their own. This
          behavior ensures that each client can retrieve its own ID
          without concern for the activity of other clients, and without
          the need for locks or transactions.
     </p>
     <p>
      The value of
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      is not changed if you set the
      <code class="literal">
       AUTO_INCREMENT
      </code>
      column of a row to a
          non-
      <span class="quote">
       “
       <span class="quote">
        magic
       </span>
       ”
      </span>
      value (that is, a value that is not
      <code class="literal">
       NULL
      </code>
      and not
      <code class="literal">
       0
      </code>
      ).
     </p>
     <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Important
      </div>
      <p>
       If you insert multiple rows using a single
       <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
        <code class="literal">
         INSERT
        </code>
       </a>
       statement,
       <a class="link" href="information-functions.html#function_last-insert-id">
        <code class="literal">
         LAST_INSERT_ID()
        </code>
       </a>
       returns the
            value generated for the
       <span class="emphasis">
        <em>
         first
        </em>
       </span>
       inserted
            row
       <span class="emphasis">
        <em>
         only
        </em>
       </span>
       . The reason for this is to
            make it possible to reproduce easily the same
       <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
        <code class="literal">
         INSERT
        </code>
       </a>
       statement against some
            other server.
      </p>
     </div>
     <p>
      For example:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa40421048"><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">USE</span> test<span class="token punctuation">;</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t <span class="token punctuation">(</span>
       id <span class="token datatype">INT</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span><span class="token punctuation">,</span>
       <span class="token keyword">name</span> <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span>
       <span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> t <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token string">'Bob'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t<span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> id <span class="token punctuation">|</span> name <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>  1 <span class="token punctuation">|</span> Bob  <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">LAST_INSERT_ID</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> LAST_INSERT_ID() <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> t <span class="token keyword">VALUES</span>
       <span class="token punctuation">(</span><span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token string">'Mary'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token string">'Jane'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token boolean">NULL</span><span class="token punctuation">,</span> <span class="token string">'Lisa'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> t<span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> id <span class="token punctuation">|</span> name <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>  1 <span class="token punctuation">|</span> Bob  <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span>  2 <span class="token punctuation">|</span> Mary <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span>  3 <span class="token punctuation">|</span> Jane <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span>  4 <span class="token punctuation">|</span> Lisa <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">LAST_INSERT_ID</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> LAST_INSERT_ID() <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                2 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
     </div>
     <p>
      Although the second
      <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
       <code class="literal">
        INSERT
       </code>
      </a>
      statement inserted three new rows into
      <code class="literal">
       t
      </code>
      ,
          the ID generated for the first of these rows was
      <code class="literal">
       2
      </code>
      , and it is this value that is returned by
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      for the
          following
      <a class="link" href="select.html" title="15.2.13 SELECT Statement">
       <code class="literal">
        SELECT
       </code>
      </a>
      statement.
     </p>
     <p>
      If you use
      <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
       <code class="literal">
        INSERT
          IGNORE
       </code>
      </a>
      and the row is ignored, the
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      remains
          unchanged from the current value (or 0 is returned if the
          connection has not yet performed a successful
      <code class="literal">
       INSERT
      </code>
      ) and, for non-transactional tables,
          the
      <code class="literal">
       AUTO_INCREMENT
      </code>
      counter is not
          incremented. For
      <code class="literal">
       InnoDB
      </code>
      tables, the
      <code class="literal">
       AUTO_INCREMENT
      </code>
      counter is incremented if
      <a class="link" href="innodb-parameters.html#sysvar_innodb_autoinc_lock_mode">
       <code class="literal">
        innodb_autoinc_lock_mode
       </code>
      </a>
      is
          set to
      <code class="literal">
       1
      </code>
      or
      <code class="literal">
       2
      </code>
      , as
          demonstrated in the following example:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46062974"><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">USE</span> test<span class="token punctuation">;</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token variable">@@innodb_autoinc_lock_mode</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> @@innodb_autoinc_lock_mode <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                          1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>t<span class="token punctuation">`</span> <span class="token punctuation">(</span>
       <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token datatype">INT</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span><span class="token punctuation">,</span>
       <span class="token punctuation">`</span>val<span class="token punctuation">`</span> <span class="token datatype">INT</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
       <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token keyword">UNIQUE</span> <span class="token keyword">KEY</span> <span class="token punctuation">`</span>i1<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>val<span class="token punctuation">`</span><span class="token punctuation">)</span>
       <span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span>InnoDB<span class="token punctuation">;</span>

<span class="token comment" spellcheck="true"># Insert two rows</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> t <span class="token punctuation">(</span>val<span class="token punctuation">)</span> <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment" spellcheck="true"># With auto_increment_offset=1, the inserted rows</span>
<span class="token comment" spellcheck="true"># result in an AUTO_INCREMENT value of 3</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
       Table<span class="token punctuation">:</span> t
Create Table<span class="token punctuation">:</span> CREATE TABLE `t` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `val` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `i1` (`val`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

# LAST_INSERT_ID() returns the first automatically generated
# value that is successfully inserted for the AUTO_INCREMENT column
</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">LAST_INSERT_ID</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> LAST_INSERT_ID() <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>

<span class="token comment" spellcheck="true"># The attempted insertion of duplicate rows fail but errors are ignored</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">INSERT</span> <span class="token keyword">IGNORE</span> <span class="token keyword">INTO</span> t <span class="token punctuation">(</span>val<span class="token punctuation">)</span> <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected (0.00 sec)</span>
<span class="token output">Records: 2  Duplicates: 2  Warnings: 0</span>

<span class="token comment" spellcheck="true"># With innodb_autoinc_lock_mode=1, the AUTO_INCREMENT counter</span>
<span class="token comment" spellcheck="true"># is incremented for the ignored rows</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
       Table<span class="token punctuation">:</span> t
Create Table<span class="token punctuation">:</span> CREATE TABLE `t` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `val` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `i1` (`val`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

# The LAST_INSERT_ID is unchanged because the previous insert was unsuccessful
</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">LAST_INSERT_ID</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> LAST_INSERT_ID() <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>                1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
     </div>
     <p>
      For more information, see
      <a class="xref" href="innodb-auto-increment-handling.html" title="17.6.1.6 AUTO_INCREMENT Handling in InnoDB">
       Section 17.6.1.6, “AUTO_INCREMENT Handling in InnoDB”
      </a>
      .
     </p>
     <a class="indexterm" name="idm46045198548288">
     </a>
     <p>
      If
      <em class="replaceable">
       <code>
        expr
       </code>
      </em>
      is given as an argument to
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      , the value of
          the argument is returned by the function and is remembered as
          the next value to be returned by
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      . This can be
          used to simulate sequences:
     </p>
     <div class="orderedlist">
      <ol class="orderedlist" type="1">
       <li class="listitem">
        <p>
         Create a table to hold the sequence counter and initialize
              it:
        </p>
        <div class="copytoclipboard-wrapper">
         <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa58073849"><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">CREATE</span> <span class="token keyword">TABLE</span> sequence <span class="token punctuation">(</span>id <span class="token datatype">INT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> sequence <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
        </div>
       </li>
       <li class="listitem">
        <p>
         Use the table to generate sequence numbers like this:
        </p>
        <div class="copytoclipboard-wrapper">
         <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa11275530"><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">UPDATE</span> sequence <span class="token keyword">SET</span> id<span class="token operator">=</span><span class="token function">LAST_INSERT_ID</span><span class="token punctuation">(</span>id<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">LAST_INSERT_ID</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
        </div>
        <p>
         The
         <a class="link" href="update.html" title="15.2.17 UPDATE Statement">
          <code class="literal">
           UPDATE
          </code>
         </a>
         statement
              increments the sequence counter and causes the next call
              to
         <a class="link" href="information-functions.html#function_last-insert-id">
          <code class="literal">
           LAST_INSERT_ID()
          </code>
         </a>
         to
              return the updated value. The
         <a class="link" href="select.html" title="15.2.13 SELECT Statement">
          <code class="literal">
           SELECT
          </code>
         </a>
         statement retrieves
              that value. The
         <a class="ulink" href="/doc/c-api/8.4/en/mysql-insert-id.html" target="_top">
          <code class="literal">
           mysql_insert_id()
          </code>
         </a>
         C API
              function can also be used to get the value. See
         <a class="ulink" href="/doc/c-api/8.4/en/mysql-insert-id.html" target="_top">
          mysql_insert_id()
         </a>
         .
        </p>
       </li>
      </ol>
     </div>
     <p>
      You can generate sequences without calling
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID()
       </code>
      </a>
      , but the
          utility of using the function this way is that the ID value is
          maintained in the server as the last automatically generated
          value. It is multi-user safe because multiple clients can
          issue the
      <a class="link" href="update.html" title="15.2.17 UPDATE Statement">
       <code class="literal">
        UPDATE
       </code>
      </a>
      statement and
          get their own sequence value with the
      <a class="link" href="select.html" title="15.2.13 SELECT Statement">
       <code class="literal">
        SELECT
       </code>
      </a>
      statement (or
      <a class="ulink" href="/doc/c-api/8.4/en/mysql-insert-id.html" target="_top">
       <code class="literal">
        mysql_insert_id()
       </code>
      </a>
      ), without
          affecting or being affected by other clients that generate
          their own sequence values.
     </p>
     <p>
      Note that
      <a class="ulink" href="/doc/c-api/8.4/en/mysql-insert-id.html" target="_top">
       <code class="literal">
        mysql_insert_id()
       </code>
      </a>
      is
          only updated after
      <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
       <code class="literal">
        INSERT
       </code>
      </a>
      and
      <a class="link" href="update.html" title="15.2.17 UPDATE Statement">
       <code class="literal">
        UPDATE
       </code>
      </a>
      statements, so you
          cannot use the C API function to retrieve the value for
      <a class="link" href="information-functions.html#function_last-insert-id">
       <code class="literal">
        LAST_INSERT_ID(
        <em class="replaceable">
         <code>
          expr
         </code>
        </em>
        )
       </code>
      </a>
      after executing other SQL statements like
      <a class="link" href="select.html" title="15.2.13 SELECT Statement">
       <code class="literal">
        SELECT
       </code>
      </a>
      or
      <a class="link" href="set-variable.html" title="15.7.6.1 SET Syntax for Variable Assignment">
       <code class="literal">
        SET
       </code>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_roles-graphml">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_roles-graphml">
       <code class="literal">
        ROLES_GRAPHML()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198511552">
     </a>
     <p>
      Returns a
      <code class="literal">
       utf8mb3
      </code>
      string containing a
          GraphML document representing memory role subgraphs. The
      <a class="link" href="privileges-provided.html#priv_role-admin">
       <code class="literal">
        ROLE_ADMIN
       </code>
      </a>
      privilege (or the
          deprecated
      <a class="link" href="privileges-provided.html#priv_super">
       <code class="literal">
        SUPER
       </code>
      </a>
      privilege) is
          required to see content in the
      <code class="literal">
       &lt;graphml&gt;
      </code>
      element. Otherwise, the
          result shows only an empty element:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa87070744"><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 function">ROLES_GRAPHML</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> ROLES_GRAPHML()                                   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> &lt;?xml version="1.0" encoding="UTF<span class="token punctuation">-</span>8"?&gt;&lt;graphml /&gt; <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_row-count">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_row-count">
       <code class="literal">
        ROW_COUNT()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198499008">
     </a>
     <p>
      <code class="literal">
       ROW_COUNT()
      </code>
      returns a value as follows:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         DDL statements: 0. This applies to statements such as
         <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
          <code class="literal">
           CREATE TABLE
          </code>
         </a>
         or
         <a class="link" href="drop-table.html" title="15.1.32 DROP TABLE Statement">
          <code class="literal">
           DROP TABLE
          </code>
         </a>
         .
        </p>
       </li>
       <li class="listitem">
        <p>
         DML statements other than
         <a class="link" href="select.html" title="15.2.13 SELECT Statement">
          <code class="literal">
           SELECT
          </code>
         </a>
         : The number of
              affected rows. This applies to statements such as
         <a class="link" href="update.html" title="15.2.17 UPDATE Statement">
          <code class="literal">
           UPDATE
          </code>
         </a>
         ,
         <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
          <code class="literal">
           INSERT
          </code>
         </a>
         , or
         <a class="link" href="delete.html" title="15.2.2 DELETE Statement">
          <code class="literal">
           DELETE
          </code>
         </a>
         (as before), but now
              also to statements such as
         <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
          <code class="literal">
           ALTER
              TABLE
          </code>
         </a>
         and
         <a class="link" href="load-data.html" title="15.2.9 LOAD DATA Statement">
          <code class="literal">
           LOAD
              DATA
          </code>
         </a>
         .
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="select.html" title="15.2.13 SELECT Statement">
          <code class="literal">
           SELECT
          </code>
         </a>
         : -1 if the statement
              returns a result set, or the number of rows
         <span class="quote">
          “
          <span class="quote">
           affected
          </span>
          ”
         </span>
         if it does not. For example, for
         <code class="literal">
          SELECT * FROM t1
         </code>
         ,
         <a class="link" href="information-functions.html#function_row-count">
          <code class="literal">
           ROW_COUNT()
          </code>
         </a>
         returns -1. For
         <code class="literal">
          SELECT * FROM t1 INTO OUTFILE
              '
          <em class="replaceable">
           <code>
            file_name
           </code>
          </em>
          '
         </code>
         ,
         <a class="link" href="information-functions.html#function_row-count">
          <code class="literal">
           ROW_COUNT()
          </code>
         </a>
         returns the
              number of rows written to the file.
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="signal.html" title="15.6.7.5 SIGNAL Statement">
          <code class="literal">
           SIGNAL
          </code>
         </a>
         statements: 0.
        </p>
       </li>
      </ul>
     </div>
     <p>
      For
      <a class="link" href="update.html" title="15.2.17 UPDATE Statement">
       <code class="literal">
        UPDATE
       </code>
      </a>
      statements, the
          affected-rows value by default is the number of rows actually
          changed. If you specify the
      <code class="literal">
       CLIENT_FOUND_ROWS
      </code>
      flag to
      <a class="ulink" href="/doc/c-api/8.4/en/mysql-real-connect.html" target="_top">
       <code class="literal">
        mysql_real_connect()
       </code>
      </a>
      when
          connecting to
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      , the affected-rows
          value is the number of rows
      <span class="quote">
       “
       <span class="quote">
        found
       </span>
       ”
      </span>
      ; that is,
          matched by the
      <code class="literal">
       WHERE
      </code>
      clause.
     </p>
     <p>
      For
      <a class="link" href="replace.html" title="15.2.12 REPLACE Statement">
       <code class="literal">
        REPLACE
       </code>
      </a>
      statements, the
          affected-rows value is 2 if the new row replaced an old row,
          because in this case, one row was inserted after the duplicate
          was deleted.
     </p>
     <p>
      For
      <a class="link" href="insert-on-duplicate.html" title="15.2.7.2 INSERT ... ON DUPLICATE KEY UPDATE Statement">
       <code class="literal">
        INSERT
          ... ON DUPLICATE KEY UPDATE
       </code>
      </a>
      statements, the
          affected-rows value per row is 1 if the row is inserted as a
          new row, 2 if an existing row is updated, and 0 if an existing
          row is set to its current values. If you specify the
      <code class="literal">
       CLIENT_FOUND_ROWS
      </code>
      flag, the affected-rows
          value is 1 (not 0) if an existing row is set to its current
          values.
     </p>
     <p>
      The
      <a class="link" href="information-functions.html#function_row-count">
       <code class="literal">
        ROW_COUNT()
       </code>
      </a>
      value is
          similar to the value from the
      <a class="ulink" href="/doc/c-api/8.4/en/mysql-affected-rows.html" target="_top">
       <code class="literal">
        mysql_affected_rows()
       </code>
      </a>
      C API
          function and the row count that 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 displays following statement execution.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa86548307"><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">INSERT</span> <span class="token keyword">INTO</span> t <span class="token keyword">VALUES</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 3 rows affected (0.00 sec)</span>
<span class="token output">Records: 3  Duplicates: 0  Warnings: 0</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ROW_COUNT</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> ROW_COUNT() <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>           3 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set (0.00 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">DELETE</span> <span class="token keyword">FROM</span> t <span class="token keyword">WHERE</span> i <span class="token keyword">IN</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 2 rows affected (0.00 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">ROW_COUNT</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> ROW_COUNT() <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span>           2 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">1 row in set (0.00 sec)</span></code></pre>
     </div>
     <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Important
      </div>
      <p>
       <a class="link" href="information-functions.html#function_row-count">
        <code class="literal">
         ROW_COUNT()
        </code>
       </a>
       is not replicated
            reliably using statement-based replication. This function is
            automatically replicated using row-based replication.
      </p>
     </div>
    </li>
    <li class="listitem">
     <a name="function_schema">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_schema">
       <code class="literal">
        SCHEMA()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198446608">
     </a>
     <p>
      This function is a synonym for
      <a class="link" href="information-functions.html#function_database">
       <code class="literal">
        DATABASE()
       </code>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_session-user">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_session-user">
       <code class="literal">
        SESSION_USER()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198437904">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_session-user">
       <code class="literal">
        SESSION_USER()
       </code>
      </a>
      is a synonym for
      <a class="link" href="information-functions.html#function_user">
       <code class="literal">
        USER()
       </code>
      </a>
      .
     </p>
     <p>
      Like
      <a class="link" href="information-functions.html#function_user">
       <code class="literal">
        USER()
       </code>
      </a>
      , this function can
          be used for the default value of a
      <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
       <code class="literal">
        VARCHAR
       </code>
      </a>
      or
      <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
       <code class="literal">
        TEXT
       </code>
      </a>
      column, as shown in the
          following
      <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
       <code class="literal">
        CREATE TABLE
       </code>
      </a>
      statement:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa8413093"><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> t <span class="token punctuation">(</span>c <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">288</span><span class="token punctuation">)</span> <span class="token function">DEFAULT</span> <span class="token punctuation">(</span><span class="token function">SESSION_USER</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_system-user">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_system-user">
       <code class="literal">
        SYSTEM_USER()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198421520">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_system-user">
       <code class="literal">
        SYSTEM_USER()
       </code>
      </a>
      is a synonym for
      <a class="link" href="information-functions.html#function_user">
       <code class="literal">
        USER()
       </code>
      </a>
      .
     </p>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       The
       <a class="link" href="information-functions.html#function_system-user">
        <code class="literal">
         SYSTEM_USER()
        </code>
       </a>
       function is
            distinct from the
       <a class="link" href="privileges-provided.html#priv_system-user">
        <code class="literal">
         SYSTEM_USER
        </code>
       </a>
       privilege. The former returns the current MySQL account
            name. The latter distinguishes the system user and regular
            user account categories (see
       <a class="xref" href="account-categories.html" title="8.2.11 Account Categories">
        Section 8.2.11, “Account Categories”
       </a>
       ).
      </p>
     </div>
     <p>
      Like
      <a class="link" href="information-functions.html#function_user">
       <code class="literal">
        USER()
       </code>
      </a>
      , this function can
          be used for the default value of a
      <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
       <code class="literal">
        VARCHAR
       </code>
      </a>
      or
      <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
       <code class="literal">
        TEXT
       </code>
      </a>
      column, as shown in the
          following
      <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
       <code class="literal">
        CREATE TABLE
       </code>
      </a>
      statement:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa69936447"><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> t <span class="token punctuation">(</span>c <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">288</span><span class="token punctuation">)</span> <span class="token function">DEFAULT</span> <span class="token punctuation">(</span><span class="token function">SYSTEM_USER</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_user">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_user">
       <code class="literal">
        USER()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198400992">
     </a>
     <p>
      Returns the current MySQL user name and host name as a string
          in the
      <code class="literal">
       utf8mb3
      </code>
      character set.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46873651"><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 function">USER</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'davida@localhost'</span></code></pre>
     </div>
     <p>
      The value indicates the user name you specified when
          connecting to the server, and the client host from which you
          connected. The value can be different from that of
      <a class="link" href="information-functions.html#function_current-user">
       <code class="literal">
        CURRENT_USER()
       </code>
      </a>
      .
     </p>
     <p>
      This function can be used for the default value of a
      <a class="link" href="char.html" title="13.3.2 The CHAR and VARCHAR Types">
       <code class="literal">
        VARCHAR
       </code>
      </a>
      or
      <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
       <code class="literal">
        TEXT
       </code>
      </a>
      column, as shown in the
          following
      <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
       <code class="literal">
        CREATE TABLE
       </code>
      </a>
      statement:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa27845520"><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> t <span class="token punctuation">(</span>c <span class="token datatype">VARCHAR</span><span class="token punctuation">(</span><span class="token number">288</span><span class="token punctuation">)</span> <span class="token function">DEFAULT</span> <span class="token punctuation">(</span><span class="token function">USER</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_version">
     </a>
     <p>
      <a class="link" href="information-functions.html#function_version">
       <code class="literal">
        VERSION()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045198383408">
     </a>
     <p>
      Returns a string that indicates the MySQL server version. The
          string uses the
      <code class="literal">
       utf8mb3
      </code>
      character set. The
          value might have a suffix in addition to the version number.
          See the description of the
      <a class="link" href="server-system-variables.html#sysvar_version">
       <code class="literal">
        version
       </code>
      </a>
      system variable in
      <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>
      This function is unsafe for statement-based replication. A
          warning is logged if you use this function when
      <a class="link" href="replication-options-binary-log.html#sysvar_binlog_format">
       <code class="literal">
        binlog_format
       </code>
      </a>
      is set to
      <code class="literal">
       STATEMENT
      </code>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa64511199"><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 function">VERSION</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token string">'8.4.3-standard'</span></code></pre>
     </div>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
