8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / B Error Messages and Common Problems / B.1 Error Message Sources and Elements
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

B.1 错误信息来源和组成元素B.1 Error Message Sources and Elements

本节讨论错误信息在 MySQL 中的来源及其包含的元素。This section discusses how error messages originate within MySQL and the elements they contain.

错误信息来源Error Message Sources

错误信息可以起源于服务器端或客户端:Error messages can originate on the server side or the client side:

  • 在服务器端,错误信息可能在启动和关闭过程中发生,也可能由于 SQL 语句执行过程中出现的问题等原因产生。On the server side, error messages may occur during the startup and shutdown processes, as a result of issues that occur during SQL statement execution, and so forth.

    • MySQL 服务器会将一些错误信息写入其错误日志。这些信息表明数据库管理员可能感兴趣的问题或需要 DBA 采取行动的问题。The MySQL server writes some error messages to its error log. These indicate issues of interest to database administrators or that require DBA action.

    • 服务器还会将其他错误信息发送给客户端程序。这些信息仅涉及特定客户端的问题。MySQL 客户端库会获取从服务器接收到的错误,并将其提供给宿主客户端程序。The server sends other error messages to client programs. These indicate issues pertaining only to a particular client. The MySQL client library takes errors received from the server and makes them available to the host client program.

  • 客户端错误信息由 MySQL 客户端库内部生成,通常涉及与服务器通信的问题。Client-side error messages are generated from within the MySQL client library, usually involving problems communicating with the server.

写入错误日志的服务器端错误信息示例:Example server-side error messages written to the error log:

  • 在启动过程中产生的此信息提供了状态或进度指示:This message produced during the startup process provides a status or progress indicator:

    2018-10-28T13:01:32.735983Z 0 [Note] [MY-010303] [Server] Skipping
    generation of SSL certificates as options related to SSL are specified.
    
  • 此信息表明一个需要 DBA 采取行动的问题:This message indicates an issue that requires DBA action:

    2018-10-02T03:20:39.410387Z 768 [ERROR] [MY-010045] [Server] Event Scheduler:
    [evtuser@localhost][myschema.e_daily] Unknown database 'mydb'
    

发送给客户端程序的示例服务器端错误消息,由 mysql 客户端显示:Example server-side error message sent to client programs, as displayed by the mysql client:

mysql> SELECT * FROM no_such_table;
ERROR 1146 (42S02): Table 'test.no_such_table' doesn't exist

来自客户端库内部的示例客户端错误消息,由 mysql 客户端显示:Example client-side error message originating from within the client library, as displayed by the mysql client:

$> mysql -h no-such-host
ERROR 2005 (HY000): Unknown MySQL server host 'no-such-host' (-2)

无论错误是源自客户端库内部还是从服务器接收,MySQL 客户端程序可能会以不同的方式响应。如刚刚所示,客户端可以显示错误消息以便用户采取纠正措施。客户端也可以在内部尝试解决或重试失败的操作,或采取其他措施。Whether an error originates from within the client library or is received from the server, a MySQL client program may respond in varying ways. As just illustrated, the client may display the error message so the user can take corrective measures. The client may instead internally attempt to resolve or retry a failed operation, or take other action.

错误消息元素Error Message Elements

当发生错误时,错误信息包括几个元素:错误代码、SQLSTATE 值和消息字符串。这些元素具有以下特点:When an error occurs, error information includes several elements: an error code, SQLSTATE value, and message string. These elements have the following characteristics:

  • 错误代码:该值为数字类型。它是 MySQL 特有的,不能移植到其他数据库系统中。Error code: This value is numeric. It is MySQL-specific and is not portable to other database systems.

    每个错误编号都有对应的符号值。示例:Each error number has a corresponding symbolic value. Examples:

    错误消息中使用的错误代码集合被划分为不同的范围;请参见 错误代码范围。The set of error codes used in error messages is partitioned into distinct ranges; see Error Code Ranges.

    在给定 MySQL 系列的正式发布(GA)版本中,错误代码是稳定的。在系列达到 GA 状态之前,新代码可能仍在开发中,并可能会发生变化。Error codes are stable across General Availability (GA) releases of a given MySQL series. Before a series reaches GA status, new codes may still be under development and are subject to change.

  • SQLSTATE 值:此值是一个五个字符的字符串(例如,'42S02')。SQLSTATE 值取自 ANSI SQL 和 ODBC,比数字错误代码更标准化。SQLSTATE 值的前两个字符表示错误类别:SQLSTATE value: This value is a five-character string (for example, '42S02'). SQLSTATE values are taken from ANSI SQL and ODBC and are more standardized than the numeric error codes. The first two characters of an SQLSTATE value indicate the error class:

    • 类别 = '00' 表示成功。Class = '00' indicates success.

    • 类别 = '01' 表示警告。Class = '01' indicates a warning.

    • Class = '02' 表示 “未找到。” 这在游标的上下文中很重要,用于控制当游标到达数据集末尾时的行为。对于没有检索到任何行的 SELECT ... INTO var_list 语句,也会出现此情况。Class = '02' indicates “not found.” This is relevant within the context of cursors and is used to control what happens when a cursor reaches the end of a data set. This condition also occurs for SELECT ... INTO var_list statements that retrieve no rows.

    • Class > '02' 表示异常。Class > '02' indicates an exception.

    对于服务器端错误,并非所有 MySQL 错误编号都有对应的 SQLSTATE 值。在这些情况下,使用 'HY000'(通用错误)。For server-side errors, not all MySQL error numbers have corresponding SQLSTATE values. In these cases, 'HY000' (general error) is used.

    对于客户端错误,SQLSTATE 值始终为 'HY000'(通用错误),因此它在区分不同客户端错误时没有意义。For client-side errors, the SQLSTATE value is always 'HY000' (general error), so it is not meaningful for distinguishing one client error from another.

  • 消息字符串:此字符串提供错误的文本描述。Message string: This string provides a textual description of the error.

错误代码范围Error Code Ranges

用于错误消息的错误代码集合被划分为不同的范围,每个范围都有其特定用途:The set of error codes used in error messages is partitioned into distinct ranges, each with its own purpose:

  • 1 到 999:全局错误代码。这个错误代码范围被称为“global”,因为它是服务器和客户端都共享的范围。1 to 999: Global error codes. This error code range is called “global” because it is a shared range that is used by the server as well as by clients.

    当该范围内的错误源于服务器端时,服务器会将其写入错误日志,将错误代码用前导零补齐至六位,并添加前缀MY-。When an error in this range originates on the server side, the server writes it to the error log, padding the error code with leading zeros to six digits and adding a prefix of MY-.

    当该范围内的错误源于客户端时,客户端库会将其提供给客户端程序,不会进行零填充或添加前缀。When an error in this range originates on the client side, the client library makes it available to the client program with no zero-padding or prefix.

  • 1,000 到 1,999:服务器错误代码,用于发送给客户端的消息。1,000 to 1,999: Server error codes reserved for messages sent to clients.

  • 2,000 到 2,999:客户端错误代码,供客户端库使用。2,000 to 2,999: Client error codes reserved for use by the client library.

  • 3,000 到 4,999:服务器错误代码保留给发送给客户端的消息。3,000 to 4,999: Server error codes reserved for messages sent to clients.

  • 5,000 到 5,999:错误代码保留供 X 插件使用,用于发送给客户端的消息。5,000 to 5,999: Error codes reserved for use by X Plugin for messages sent to clients.

  • 10,000 到 49,999:服务器错误代码保留用于写入错误日志的消息(不发送给客户端)。10,000 to 49,999: Server error codes reserved for messages to be written to the error log (not sent to clients).

    当发生此范围内的错误时,服务器将其写入错误日志,并将错误代码用前导零填充为六位数字,并添加 MY- 前缀。When an error in this range occurs, the server writes it to the error log, padding the error code with leading zeros to six digits and adding a prefix of MY-.

  • 50,000 到 51,999:错误代码保留供第三方使用。50,000 to 51,999: Error codes reserved for use by third parties.

服务器处理写入错误日志的错误消息与发送给客户端的错误消息不同:The server handles error messages written to the error log differently from error messages sent to clients:

  • 当服务器将消息写入错误日志时,它会将错误代码填充为六位数的前导零,并添加前缀 MY-(例如:MY-000022,MY-010048)。When the server writes a message to the error log, it pads the error code with leading zeros to six digits and adds a prefix of MY- (examples: MY-000022, MY-010048).

  • 当服务器向客户端程序发送消息时,它不会在错误代码前添加零填充或前缀(示例:1036, 3013)。When the server sends a message to a client program, it adds no zero-padding or prefix to the error code (examples: 1036, 3013).