<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="error-interfaces">
      </a>
      B.2 Error Information Interfaces
     </h2>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045054701616">
  </a>
  <a class="indexterm" name="idm46045054700160">
  </a>
  <p>
   Error messages can originate on the server side or the client
      side, and each error message includes an error code, SQLSTATE
      value, and message string, as described in
   <a class="xref" href="error-message-elements.html" title="B.1 Error Message Sources and Elements">
    Section B.1, “Error Message Sources and Elements”
   </a>
   . For lists of
      server-side, client-side, and global (shared between server and
      clients) errors, see
   <a class="ulink" href="/doc/mysql-errors/8.4/en/" target="_top">
    MySQL 8.4 Error Message Reference
   </a>
   .
  </p>
  <p>
   For error checking from within programs, use error code numbers or
      symbols, not error message strings. Message strings do not change
      often, but it is possible. Also, if the database administrator
      changes the language setting, that affects the language of message
      strings; see
   <a class="xref" href="error-message-language.html" title="12.12 Setting the Error Message Language">
    Section 12.12, “Setting the Error Message Language”
   </a>
   .
  </p>
  <p>
   Error information in MySQL is available in the server error log,
      at the SQL level, from within client programs, and at the command
      line.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="xref" href="error-interfaces.html#error-interface-log" title="Error Log">
       Error Log
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="error-interfaces.html#error-interface-sql" title="SQL Error Message Interface">
       SQL Error Message Interface
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="error-interfaces.html#error-interface-client" title="Client Error Message Interface">
       Client Error Message Interface
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="error-interfaces.html#error-interface-command" title="Command-Line Error Message Interface">
       Command-Line Error Message Interface
      </a>
     </p>
    </li>
   </ul>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="error-interface-log">
       </a>
       Error Log
      </h3>
     </div>
    </div>
   </div>
   <p>
    On the server side, some messages are intended for the error
        log. For information about configuring where and how the server
        writes the log, see
    <a class="xref" href="error-log.html" title="7.4.2 The Error Log">
     Section 7.4.2, “The Error Log”
    </a>
    .
   </p>
   <p>
    Other server error messages are intended to be sent to client
        programs and are available as described in
    <a class="xref" href="error-interfaces.html#error-interface-client" title="Client Error Message Interface">
     Client Error Message Interface
    </a>
    .
   </p>
   <p>
    The range within which a particular error code lies determines
        whether the server writes an error message to the error log or
        sends it to clients. For information about these ranges, see
    <a class="xref" href="error-message-elements.html#error-code-ranges" title="Error Code Ranges">
     Error Code Ranges
    </a>
    .
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="error-interface-sql">
       </a>
       SQL Error Message Interface
      </h3>
     </div>
    </div>
   </div>
   <p>
    At the SQL level, there are several sources of error information
        in MySQL:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       SQL statement warning and error information is available
            through the
       <a class="link" href="show-warnings.html" title="15.7.7.42 SHOW WARNINGS Statement">
        <code class="literal">
         SHOW WARNINGS
        </code>
       </a>
       and
       <a class="link" href="show-errors.html" title="15.7.7.18 SHOW ERRORS Statement">
        <code class="literal">
         SHOW ERRORS
        </code>
       </a>
       statements. The
       <a class="link" href="server-system-variables.html#sysvar_warning_count">
        <code class="literal">
         warning_count
        </code>
       </a>
       system
            variable indicates the number of errors, warnings, and notes
            (with notes excluded if the
       <a class="link" href="server-system-variables.html#sysvar_sql_notes">
        <code class="literal">
         sql_notes
        </code>
       </a>
       system variable
            is disabled). The
       <a class="link" href="server-system-variables.html#sysvar_error_count">
        <code class="literal">
         error_count
        </code>
       </a>
       system variable
            indicates the number of errors. Its value excludes warnings
            and notes.
      </p>
     </li>
     <li class="listitem">
      <p>
       The
       <a class="link" href="get-diagnostics.html" title="15.6.7.3 GET DIAGNOSTICS Statement">
        <code class="literal">
         GET DIAGNOSTICS
        </code>
       </a>
       statement
            may be used to inspect the diagnostic information in the
            diagnostics area. See
       <a class="xref" href="get-diagnostics.html" title="15.6.7.3 GET DIAGNOSTICS Statement">
        Section 15.6.7.3, “GET DIAGNOSTICS Statement”
       </a>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       <a class="link" href="show-replica-status.html" title="15.7.7.35 SHOW REPLICA STATUS Statement">
        <code class="literal">
         SHOW REPLICA STATUS
        </code>
       </a>
       statement
            output includes information about replication errors
            occurring on replica servers.
      </p>
     </li>
     <li class="listitem">
      <p>
       <a class="link" href="show-engine.html" title="15.7.7.16 SHOW ENGINE Statement">
        <code class="literal">
         SHOW ENGINE
            INNODB STATUS
        </code>
       </a>
       statement output includes
            information about the most recent foreign key error if a
       <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
        <code class="literal">
         CREATE TABLE
        </code>
       </a>
       statement for an
       <a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine">
        <code class="literal">
         InnoDB
        </code>
       </a>
       table fails.
      </p>
     </li>
    </ul>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="error-interface-client">
       </a>
       Client Error Message Interface
      </h3>
     </div>
    </div>
   </div>
   <p>
    Client programs receive errors from two sources:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       Errors that originate on the client side from within the
            MySQL client library.
      </p>
     </li>
     <li class="listitem">
      <p>
       Errors that originate on the server side and are sent to the
            client by the server. These are received within the client
            library, which makes them available to the host client
            program.
      </p>
     </li>
    </ul>
   </div>
   <p>
    The range within which a particular error code lies determines
        whether it originated from within the client library or was
        received by the client from the server. For information about
        these ranges, see
    <a class="xref" href="error-message-elements.html#error-code-ranges" title="Error Code Ranges">
     Error Code Ranges
    </a>
    .
   </p>
   <p>
    Regardless of whether an error originates from within the client
        library or is received from the server, a MySQL client program
        obtains the error code, SQLSTATE value, message string, and
        other related information by calling C API functions in the
        client library:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       <a class="ulink" href="/doc/c-api/8.4/en/mysql-errno.html" target="_top">
        <code class="literal">
         mysql_errno()
        </code>
       </a>
       returns the
            MySQL error code.
      </p>
     </li>
     <li class="listitem">
      <p>
       <a class="ulink" href="/doc/c-api/8.4/en/mysql-sqlstate.html" target="_top">
        <code class="literal">
         mysql_sqlstate()
        </code>
       </a>
       returns the
            SQLSTATE value.
      </p>
     </li>
     <li class="listitem">
      <p>
       <a class="ulink" href="/doc/c-api/8.4/en/mysql-error.html" target="_top">
        <code class="literal">
         mysql_error()
        </code>
       </a>
       returns the
            message string.
      </p>
     </li>
     <li class="listitem">
      <p>
       <a class="ulink" href="/doc/c-api/8.4/en/mysql-stmt-errno.html" target="_top">
        <code class="literal">
         mysql_stmt_errno()
        </code>
       </a>
       ,
       <a class="ulink" href="/doc/c-api/8.4/en/mysql-stmt-sqlstate.html" target="_top">
        <code class="literal">
         mysql_stmt_sqlstate()
        </code>
       </a>
       , and
       <a class="ulink" href="/doc/c-api/8.4/en/mysql-stmt-error.html" target="_top">
        <code class="literal">
         mysql_stmt_error()
        </code>
       </a>
       are the
            corresponding error functions for prepared statements.
      </p>
     </li>
     <li class="listitem">
      <p>
       <a class="ulink" href="/doc/c-api/8.4/en/mysql-warning-count.html" target="_top">
        <code class="literal">
         mysql_warning_count()
        </code>
       </a>
       returns the number of errors, warnings, and notes for the
            most recent statement.
      </p>
     </li>
    </ul>
   </div>
   <p>
    For descriptions of the client library error functions, see
    <a class="ulink" href="/doc/c-api/8.4/en/" target="_top">
     MySQL 8.4 C API Developer Guide
    </a>
    .
   </p>
   <p>
    A MySQL client program may respond to an error in varying ways.
        The client may display the error message so the user can take
        corrective measures, internally attempt to resolve or retry a
        failed operation, or take other action. For example, (using 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), a failure to connect to the
        server might result in this message:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa35939543"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">mysql</span> <span class="token property">-h</span> no-such-host
<span class="token output">ERROR 2005 (HY000)<span class="token punctuation">:</span> Unknown MySQL server host 'no-such-host' (-2)</span></code></pre>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="error-interface-command">
       </a>
       Command-Line Error Message Interface
      </h3>
     </div>
    </div>
   </div>
   <p>
    The
    <a class="link" href="perror.html" title="6.8.1 perror — Display MySQL Error Message Information">
     <span class="command">
      <strong>
       perror
      </strong>
     </span>
    </a>
    program provides information from
        the command line about error numbers. See
    <a class="xref" href="perror.html" title="6.8.1 perror — Display MySQL Error Message Information">
     Section 6.8.1, “perror — Display MySQL Error Message Information”
    </a>
    .
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa30541227"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">perror</span> 1231
MySQL error code MY-001231 <span class="token punctuation">(</span>ER_WRONG_VALUE_FOR_VAR<span class="token punctuation">)</span><span class="token punctuation">:</span> Variable <span class="token atrule">'%-.64s'</span>
can<span class="token atrule">'t be set to the value of '</span>%-<span class="token punctuation">.</span>200s'</code></pre>
   </div>
   <p>
    For MySQL NDB Cluster errors, use
    <a class="link" href="mysql-cluster-programs-ndb-perror.html" title="25.5.16 ndb_perror — Obtain NDB Error Message Information">
     <span class="command">
      <strong>
       ndb_perror
      </strong>
     </span>
    </a>
    .
        See
    <a class="xref" href="mysql-cluster-programs-ndb-perror.html" title="25.5.16 ndb_perror — Obtain NDB Error Message Information">
     Section 25.5.16, “ndb_perror — Obtain NDB Error Message Information”
    </a>
    .
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa19928922"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">ndb_perror</span> 323
NDB error code 323<span class="token punctuation">:</span> Invalid nodegroup id<span class="token punctuation">,</span> nodegroup already existing<span class="token punctuation">:</span>
Permanent error<span class="token punctuation">:</span> Application error</code></pre>
   </div>
  </div>
 </div>
 <br/>
</div>
