欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

通过一次服务器错误代码和消息了解mysql如何处理异常

程序员文章站 2024-01-28 20:30:10
MySQL programs have access to several types of error information when the server returns a...

MySQL programs have access to several types of error information when the server returns an error. For example, the mysql client program displays errors using the following format:

当服务器返回错误时,MySQL程序可以访问几种类型的错误信息。例如,mysql客户机程序使用以下格式显示错误:

shell> SELECT * FROM no_such_table;

ERROR 1146 (42S02): Table 'test.no_such_table' doesn't exist

The message displayed contains three types of information:

所显示的消息包含三种类型的信息:

A numeric error code (1146). This number is MySQL-specific and is not portable to other database systems.

一个数字错误码(1146)。这个数字是mysql特有的,不能移植到其他数据库系统

A five-character SQLSTATE value ('42S02'). The values are taken from ANSI SQL and ODBC and are more standardized. Not all MySQL error numbers have corresponding SQLSTATE values. In these cases, 'HY000' (general error) is used.

一个5字符的SQLSTATE值('42S02')。这些值取自ANSI SQL和ODBC,并且更加标准化。不是所有的MySQL错误编号都有相应的SQLSTATE值。在这些情况下,使用“HY000”(一般错误)。

A message string that provides a textual description of the error.

一个消息字符串,它提供了错误的文本描述。

For error checking, use error codes, not error messages. Error messages do not change often, but it is possible. Also if the database administrator changes the language setting, that affects the language of error messages.

对于错误检查,使用错误代码,而不是错误消息。错误消息不会经常更改,但这是可能的。另外,如果数据库管理员更改了语言设置,则会影响错误消息的语言。

Error codes are stable across GA releases of a given MySQL series. Before a series reaches GA status, new codes may still be under development and subject to change.

在给定的MySQL系列的GA版本中(mysql5.7ga版本),错误代码是稳定的。在一个系列达到GA的状态之前,新的代码可能还在开发中,并且可能会发生变化。

Server error information comes from the following source files. For details about the way that error information is defined, see the MySQL Internals Manual.

服务器错误信息来自以下的源文件。有关错误信息定义方式的详细信息,请参阅MySQL Internals手册。

Error message information is listed in the share/errmsg-utf8.txt file. %d and %s represent numbers and strings, respectively, that are substituted into the Message values when they are displayed.

错误消息信息列在 share/errmsg-utf8.txt 文件。 %d and %s 分别表示数字和字符串。它们在显示时被替换为消息值

The Error values listed in share/errmsg-utf8.txt are used to generate the definitions in the include/mysqld_error.h and include/mysqld_ername.h MySQL source files.

share/errmsg-utf8.txt中列出的错误值。用于生成定义include/mysqld_error.h 和 include/mysqld_ername.h mysql源文件

The SQLSTATE values listed in share/errmsg-utf8.txt are used to generate the definitions in the include/sql_state.h MySQL source file.

SQLSTATE的中列出错误值 share/errmsg-utf8.txt 用于生成定义。在include/sql_state.h mysql source file 源文件

Because updates are frequent, it is possible that those files will contain additional error information not listed here.

因为更新是频繁的,所以这些文件可能包含没有在这里列出的附加错误信息。

Error: 1000 SQLSTATE: HY000 (ER_HASHCHK)

Message: hashchk

Unused.

Error: 1001 SQLSTATE: HY000 (ER_NISAMCHK)

Message: isamchk

Unused.

Error: 1002 SQLSTATE: HY000 (ER_NO)

Message: NO

用于其他信息的构建。

Used in the construction of other messages.

Error: 1003 SQLSTATE: HY000 (ER_YES)

Message: YES

用于其他信息的构建。

Used in the construction of other messages.

扩展解释格式生成注释消息。ER_YES在随后的显示警告输出中用于这些消息的代码列中。

Extended EXPLAIN format generates Note messages. ER_YES is used in the Code column for these messages in subsequent SHOW WARNINGS output.

Error: 1004 SQLSTATE: HY000 (ER_CANT_CREATE_FILE)

不能创建文件

Message: Can't create file '%s' (errno: %d - %s)

未能创建或复制某个操作所需的文件时发生。

Occurs for failure to create or copy a file needed for some operation.

可能的原因:源文件的权限问题;目标文件已经存在,但不可写。

Possible causes: Permissions problem for source file; destination file already exists but is not writeable.

Error: 1005 SQLSTATE: HY000 (ER_CANT_CREATE_TABLE)

无法创建表

Message: Can't create table '%s' (errno: %d)

InnoDB在无法创建表时报告此错误。如果错误消息引用错误150,表创建失败,因为外键约束没有正确地形成。如果错误消息指错误1,表创建可能失败,因为表包含一个列名称匹配的内部InnoDB表的名称。

InnoDB reports this error when a table cannot be created. If the error message refers to error 150, table creation failed because a foreign key constraint was not correctly formed. If the error message refers to error 1, table creation probably failed because the table includes a column name that matched the name of an internal InnoDB table.

Error: 1006 SQLSTATE: HY000 (ER_CANT_CREATE_DB)

无法创建数据库

Message: Can't create database '%s' (errno: %d)