MySQL 服务器可以在不同的 SQL 模式下运行,并且可以根据 sql_mode 系统变量。 DBA 可以设置全局 SQL 模式来匹配站点服务器操作要求,每个应用程序都可以根据自己的要求设置其会话 SQL 模式。The MySQL server can operate in different SQL modes, and can apply
these modes differently for different clients, depending on the
value of the sql_mode system
variable. DBAs can set the global SQL mode to match site server
operating requirements, and each application can set its session
SQL mode to its own requirements.
模式会影响 MySQL 支持的 SQL 语法及其执行的数据验证检查。这样可以更轻松地在不同环境中使用 MySQL 以及将 MySQL 与其他数据库服务器一起使用。Modes affect the SQL syntax MySQL supports and the data validation checks it performs. This makes it easier to use MySQL in different environments and to use MySQL together with other database servers.
有关 MySQL 中服务器 SQL 模式常见问题的答案,请参见 第 A.3 节,“MySQL 8.4 FAQ:服务器 SQL 模式”。For answers to questions often asked about server SQL modes in MySQL, see Section A.3, “MySQL 8.4 FAQ: Server SQL Mode”.
在使用 InnoDB 表时,还请考虑 innodb_strict_mode 系统变量。它为 InnoDB 表启用额外的错误检查。When working with InnoDB tables, consider also
the innodb_strict_mode system
variable. It enables additional error checks for
InnoDB tables.
MySQL 8.4 中的默认 SQL 模式包括这些模式:ONLY_FULL_GROUP_BY、STRICT_TRANS_TABLES、NO_ZERO_IN_DATE、NO_ZERO_DATE、ERROR_FOR_DIVISION_BY_ZERO 和 NO_ENGINE_SUBSTITUTION。The default SQL mode in MySQL 8.4 includes these
modes: ONLY_FULL_GROUP_BY,
STRICT_TRANS_TABLES,
NO_ZERO_IN_DATE,
NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,
and NO_ENGINE_SUBSTITUTION.
要在服务器启动时设置 SQL 模式,请在命令行中使用 --sql-mode=" 选项,或者在选项文件中使用 modes"sql-mode=",如 modes"my.cnf(Unix 操作系统)或 my.ini(Windows)。modes 是由逗号分隔的不同模式列表。要明确清除 SQL 模式,请在命令行中将其设置为空字符串,使用 --sql-mode="",或在选项文件中使用 sql-mode=""。To set the SQL mode at server startup, use the
--sql-mode="
option on the command line, or
modes"sql-mode="
in an option file such as modes"my.cnf (Unix
operating systems) or my.ini (Windows).
modes is a list of different modes
separated by commas. To clear the SQL mode explicitly, set it to
an empty string using
--sql-mode="" on the command
line, or sql-mode="" in an option
file.
MySQL 安装程序可能会在安装过程中配置 SQL 模式。MySQL installation programs may configure the SQL mode during the installation process.
如果 SQL 模式与默认值或您预期的不同,请检查服务器在启动时读取的选项文件中的设置。If the SQL mode differs from the default or from what you expect, check for a setting in an option file that the server reads at startup.
要在运行时更改 SQL 模式,请使用 SET 语句设置全局或会话 sql_mode 系统变量:To change the SQL mode at runtime, set the global or session
sql_mode system variable using
a SET
statement:
SET GLOBAL sql_mode = 'modes'; SET SESSION sql_mode = 'modes';
设置 GLOBAL 变量需要 SYSTEM_VARIABLES_ADMIN 权限(或已弃用的 SUPER 权限),并会影响从那个时间点开始连接的所有客户端的操作。设置 SESSION 变量仅影响当前客户端。每个客户端可以随时更改其会话 sql_mode 值。Setting the GLOBAL variable requires the
SYSTEM_VARIABLES_ADMIN privilege
(or the deprecated SUPER
privilege) and affects the operation of all clients that connect
from that time on. Setting the SESSION
variable affects only the current client. Each client can change
its session sql_mode value at
any time.
要确定当前的全局或会话 sql_mode 设置,请选择其值:To determine the current global or session
sql_mode setting, select its
value:
SELECT @@GLOBAL.sql_mode; SELECT @@SESSION.sql_mode;
SQL 模式和用户定义的分区。 在创建并向分区表插入数据后更改服务器 SQL 模式可能会导致这些表的行为发生重大变化,并可能导致数据丢失或损坏。强烈建议您在创建使用用户定义分区的表后,绝不要更改 SQL 模式。SQL mode and user-defined partitioning. Changing the server SQL mode after creating and inserting data into partitioned tables can cause major changes in the behavior of such tables, and could lead to loss or corruption of data. It is strongly recommended that you never change the SQL mode once you have created tables employing user-defined partitioning.
在复制分区表时,源端和副本的 SQL 模式不同也可能导致问题。为了获得最佳效果,您应始终在源端和副本上使用相同的服务器 SQL 模式。When replicating partitioned tables, differing SQL modes on the source and replica can also lead to problems. For best results, you should always use the same server SQL mode on the source and replica.
欲了解更多信息,请参见 第 26.6 节,“分区的限制和约束”。For more information, see Section 26.6, “Restrictions and Limitations on Partitioning”.
最重要的 sql_mode 值可能是这些:The most important sql_mode
values are probably these:
此模式更改语法和行为以更接近标准 SQL。它是本节末尾列出的特殊 组合模式 之一。This mode changes syntax and behavior to conform more closely to standard SQL. It is one of the special combination modes listed at the end of this section.
如果一个值无法按给定方式插入到事务表中,则中止语句。对于非事务表,如果值出现在单行语句中或多行语句的第一行,则中止语句。本节后面将提供更多详细信息。If a value could not be inserted as given into a transactional table, abort the statement. For a nontransactional table, abort the statement if the value occurs in a single-row statement or the first row of a multiple-row statement. More details are given later in this section.
让 MySQL 表现得像一个 “传统” 的 SQL 数据库系统。对此模式的简单描述是 “在向列插入错误值时发出错误而不是警告”。它是本节结尾列出的 组合模式 之一。Make MySQL behave like a “traditional” SQL database system. A simple description of this mode is “give an error instead of a warning” when inserting an incorrect value into a column. It is one of the special combination modes listed at the end of this section.
Note启用
TRADITIONAL模式时,一旦发生错误,INSERT或UPDATE操作将立即中止。如果您使用的是非事务性存储引擎,这可能不是您想要的,因为在错误发生之前所做的数据更改可能不会回滚,从而导致“部分完成”的更新。WithTRADITIONALmode enabled, anINSERTorUPDATEaborts as soon as an error occurs. If you are using a nontransactional storage engine, this may not be what you want because data changes made prior to the error may not be rolled back, resulting in a “partially done” update.
当本手册提到 “严格模式” 时,它指的是启用了 STRICT_TRANS_TABLES 或 STRICT_ALL_TABLES 中任意一个或两个的模式。When this manual refers to “strict mode,” it means
a mode with either or both
STRICT_TRANS_TABLES or
STRICT_ALL_TABLES enabled.
以下列表描述了所有支持的 SQL 模式:The following list describes all supported SQL modes:
ALLOW_INVALID_DATESALLOW_INVALID_DATES不执行完整的日期检查。只检查月份是否在 1 到 12 之间,日期是否在 1 到 31 之间。这对于从三个不同字段获取年、月、日并且存储用户输入内容而不进行日期验证的 Web 应用可能很有用。此模式适用于
DATE和DATETIME列。不适用于TIMESTAMP列,TIMESTAMP 列始终需要有效日期。Do not perform full checking of dates. Check only that the month is in the range from 1 to 12 and the day is in the range from 1 to 31. This may be useful for Web applications that obtain year, month, and day in three different fields and store exactly what the user inserted, without date validation. This mode applies toDATEandDATETIMEcolumns. It does not apply toTIMESTAMPcolumns, which always require a valid date.当
ALLOW_INVALID_DATES被禁用时,服务器要求月份和日期值必须合法,而不仅仅是分别在 1 到 12 和 1 到 31 之间。禁用严格模式时,无效日期例如'2004-04-31'会被转换为'0000-00-00'并生成警告。启用严格模式时,无效日期会生成错误。要允许这种日期,请启用ALLOW_INVALID_DATES。WithALLOW_INVALID_DATESdisabled, the server requires that month and day values be legal, and not merely in the range 1 to 12 and 1 to 31, respectively. With strict mode disabled, invalid dates such as'2004-04-31'are converted to'0000-00-00'and a warning is generated. With strict mode enabled, invalid dates generate an error. To permit such dates, enableALLOW_INVALID_DATES.将
"视为标识符引用字符(类似`引号字符),而不是字符串引号字符。启用此模式后,仍然可以使用`来引用标识符。启用ANSI_QUOTES后,不能使用双引号来引用字符串字面值,因为它们会被解释为标识符。Treat"as an identifier quote character (like the`quote character) and not as a string quote character. You can still use`to quote identifiers with this mode enabled. WithANSI_QUOTESenabled, you cannot use double quotation marks to quote literal strings because they are interpreted as identifiers.ERROR_FOR_DIVISION_BY_ZEROERROR_FOR_DIVISION_BY_ZEROERROR_FOR_DIVISION_BY_ZERO模式影响除以零的处理,包括MOD(。对于数据更改操作(N,0)INSERT,UPDATE),其效果也取决于是否启用了严格 SQL 模式。TheERROR_FOR_DIVISION_BY_ZEROmode affects handling of division by zero, which includesMOD(. For data-change operations (N,0)INSERT,UPDATE), its effect also depends on whether strict SQL mode is enabled.如果未启用此模式,除以零会插入
NULL,并且不会产生警告。If this mode is not enabled, division by zero insertsNULLand produces no warning.如果启用了此模式,除以零会插入
NULL,并且会产生警告。If this mode is enabled, division by zero insertsNULLand produces a warning.如果启用了此模式和严格模式,除以零会产生错误,除非同时指定了
IGNORE。对于INSERT IGNORE和UPDATE IGNORE,除以零会插入NULL并产生警告。If this mode and strict mode are enabled, division by zero produces an error, unlessIGNOREis given as well. ForINSERT IGNOREandUPDATE IGNORE, division by zero insertsNULLand produces a warning.
对于
SELECT,除以零会返回NULL。启用ERROR_FOR_DIVISION_BY_ZERO同样会产生警告,无论是否启用严格模式。ForSELECT, division by zero returnsNULL. EnablingERROR_FOR_DIVISION_BY_ZEROcauses a warning to be produced as well, regardless of whether strict mode is enabled.ERROR_FOR_DIVISION_BY_ZERO已被弃用。ERROR_FOR_DIVISION_BY_ZERO不是严格模式的一部分,但应与严格模式一起使用,并且默认启用。如果启用了ERROR_FOR_DIVISION_BY_ZERO而没有同时启用严格模式,或者反之,则会发生警告。ERROR_FOR_DIVISION_BY_ZEROis deprecated.ERROR_FOR_DIVISION_BY_ZEROis not part of strict mode, but should be used in conjunction with strict mode and is enabled by default. A warning occurs ifERROR_FOR_DIVISION_BY_ZEROis enabled without also enabling strict mode or vice versa.由于
ERROR_FOR_DIVISION_BY_ZERO已被弃用,您应预期在未来的 MySQL 版本中,它将作为单独的模式名称被移除,其效果将包含在严格 SQL 模式的效果中。BecauseERROR_FOR_DIVISION_BY_ZEROis deprecated, you should expect it to be removed in a future MySQL release as a separate mode name and its effect included in the effects of strict SQL mode.HIGH_NOT_PRECEDENCEHIGH_NOT_PRECEDENCENOT运算符的优先级是这样的:像NOT a BETWEEN b AND c这样的表达式会被解析为NOT (a BETWEEN b AND c)。在 MySQL 的某些旧版本中,该表达式被解析为(NOT a) BETWEEN b AND c。通过启用HIGH_NOT_PRECEDENCESQL 模式,可以获得旧的高优先级行为。The precedence of theNOToperator is such that expressions such asNOT a BETWEEN b AND care parsed asNOT (a BETWEEN b AND c). In some older versions of MySQL, the expression was parsed as(NOT a) BETWEEN b AND c. The old higher-precedence behavior can be obtained by enabling theHIGH_NOT_PRECEDENCESQL mode.mysql>
SET sql_mode = '';mysql>SELECT NOT 1 BETWEEN -5 AND 5;-> 0 mysql>SET sql_mode = 'HIGH_NOT_PRECEDENCE';mysql>SELECT NOT 1 BETWEEN -5 AND 5;-> 1允许在函数名和
(字符之间留空格。这会导致内置函数名被视为保留字。因此,与函数名相同的标识符必须按照 第 11.2 节,“模式对象名称” 中的说明加引号。例如,由于存在COUNT()函数,在下列语句中将count用作表名会导致错误:Permit spaces between a function name and the(character. This causes built-in function names to be treated as reserved words. As a result, identifiers that are the same as function names must be quoted as described in Section 11.2, “Schema Object Names”. For example, because there is aCOUNT()function, the use ofcountas a table name in the following statement causes an error:mysql>
CREATE TABLE count (i INT);ERROR 1064 (42000): You have an error in your SQL syntax表名应该加引号:The table name should be quoted:
mysql>
CREATE TABLE `count` (i INT);Query OK, 0 rows affected (0.00 sec)IGNORE_SPACESQL 模式适用于内置函数,而不适用于可加载函数或存储函数。无论是否启用了IGNORE_SPACE,在可加载函数或存储函数名称后都有空格始终是允许的。TheIGNORE_SPACESQL mode applies to built-in functions, not to loadable functions or stored functions. It is always permissible to have spaces after a loadable function or stored function name, regardless of whetherIGNORE_SPACEis enabled.有关
IGNORE_SPACE的进一步讨论,请参见 第 11.2.5 节,“函数名称解析和解析”。For further discussion ofIGNORE_SPACE, see Section 11.2.5, “Function Name Parsing and Resolution”.NO_AUTO_VALUE_ON_ZERONO_AUTO_VALUE_ON_ZERONO_AUTO_VALUE_ON_ZERO会影响AUTO_INCREMENT列的处理方式。通常,你可以通过向该列插入NULL或0来生成下一个序列号。NO_AUTO_VALUE_ON_ZERO会抑制0的这种行为,使得只有NULL才会生成下一个序列号。NO_AUTO_VALUE_ON_ZEROaffects handling ofAUTO_INCREMENTcolumns. Normally, you generate the next sequence number for the column by inserting eitherNULLor0into it.NO_AUTO_VALUE_ON_ZEROsuppresses this behavior for0so that onlyNULLgenerates the next sequence number.如果在表的
AUTO_INCREMENT列中存储了0,这种模式可能会很有用。(顺便说一下,存储0并不是推荐的做法。)例如,如果你使用 mysqldump 导出表,然后再重新加载它,当 MySQL 遇到0值时通常会生成新的序列号,从而导致表的内容与导出的内容不同。在重新加载转储文件之前启用NO_AUTO_VALUE_ON_ZERO可以解决此问题。因此,mysqldump 会自动在其输出中包含一条启用NO_AUTO_VALUE_ON_ZERO的语句。This mode can be useful if0has been stored in a table'sAUTO_INCREMENTcolumn. (Storing0is not a recommended practice, by the way.) For example, if you dump the table with mysqldump and then reload it, MySQL normally generates new sequence numbers when it encounters the0values, resulting in a table with contents different from the one that was dumped. EnablingNO_AUTO_VALUE_ON_ZERObefore reloading the dump file solves this problem. For this reason, mysqldump automatically includes in its output a statement that enablesNO_AUTO_VALUE_ON_ZERO.启用此模式将禁用在字符串和标识符中使用反斜杠字符(
\)作为转义字符。在启用此模式后,反斜杠将变为普通字符,与其他字符一样,并且LIKE表达式的默认转义序列将被更改为不使用任何转义字符。Enabling this mode disables the use of the backslash character (\) as an escape character within strings and identifiers. With this mode enabled, backslash becomes an ordinary character like any other, and the default escape sequence forLIKEexpressions is changed so that no escape character is used.在创建表时,忽略所有
INDEX DIRECTORY和DATA DIRECTORY指令。此选项在从属服务器上非常有用。When creating a table, ignore allINDEX DIRECTORYandDATA DIRECTORYdirectives. This option is useful on replica servers.当语句如
CREATE TABLE或ALTER TABLE指定的存储引擎被禁用或未编译时,控制是否自动替换为默认存储引擎。Control automatic substitution of the default storage engine when a statement such asCREATE TABLEorALTER TABLEspecifies a storage engine that is disabled or not compiled in.默认情况下,
NO_ENGINE_SUBSTITUTION是启用的。By default,NO_ENGINE_SUBSTITUTIONis enabled.由于存储引擎可以在运行时插拔,不可用的引擎也以同样的方式处理:Because storage engines can be pluggable at runtime, unavailable engines are treated the same way:
当
NO_ENGINE_SUBSTITUTION被禁用时,对于CREATE TABLE,将使用默认存储引擎,如果所需存储引擎不可用,将出现警告。对于ALTER TABLE,将出现警告且表不会被修改。WithNO_ENGINE_SUBSTITUTIONdisabled, forCREATE TABLEthe default engine is used and a warning occurs if the desired engine is unavailable. ForALTER TABLE, a warning occurs and the table is not altered.当
NO_ENGINE_SUBSTITUTION被启用时,如果所需存储引擎不可用,将发生错误且表不会被创建或修改。WithNO_ENGINE_SUBSTITUTIONenabled, an error occurs and the table is not created or altered if the desired engine is unavailable.整数值之间的减法,如果其中一个是
UNSIGNED类型,默认会产生无符号结果。如果结果本来会是负数,则会产生错误:Subtraction between integer values, where one is of typeUNSIGNED, produces an unsigned result by default. If the result would otherwise have been negative, an error results:mysql>
SET sql_mode = '';Query OK, 0 rows affected (0.00 sec) mysql>SELECT CAST(0 AS UNSIGNED) - 1;ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(cast(0 as unsigned) - 1)'如果启用了
NO_UNSIGNED_SUBTRACTIONSQL 模式,结果将为负数:If theNO_UNSIGNED_SUBTRACTIONSQL mode is enabled, the result is negative:mysql>
SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';mysql>SELECT CAST(0 AS UNSIGNED) - 1;+-------------------------+ | CAST(0 AS UNSIGNED) - 1 | +-------------------------+ | -1 | +-------------------------+如果此类操作的结果用于更新
UNSIGNED整数列,则结果会被限制为该列类型的最大值,或者在启用NO_UNSIGNED_SUBTRACTION时限制为 0。在启用严格 SQL 模式时,会发生错误,列保持不变。If the result of such an operation is used to update anUNSIGNEDinteger column, the result is clipped to the maximum value for the column type, or clipped to 0 ifNO_UNSIGNED_SUBTRACTIONis enabled. With strict SQL mode enabled, an error occurs and the column remains unchanged.当
NO_UNSIGNED_SUBTRACTION启用时,减法结果为有符号,即使任何运算数是无符号的。例如,比对表t1中列c2与表t2中列c2的类型:WhenNO_UNSIGNED_SUBTRACTIONis enabled, the subtraction result is signed, even if any operand is unsigned. For example, compare the type of columnc2in tablet1with that of columnc2in tablet2:mysql>
SET sql_mode='';mysql>CREATE TABLE test (c1 BIGINT UNSIGNED NOT NULL);mysql>CREATE TABLE t1 SELECT c1 - 1 AS c2 FROM test;mysql>DESCRIBE t1;+-------+---------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------------------+------+-----+---------+-------+ | c2 | bigint(21) unsigned | NO | | 0 | | +-------+---------------------+------+-----+---------+-------+ mysql>SET sql_mode='NO_UNSIGNED_SUBTRACTION';mysql>CREATE TABLE t2 SELECT c1 - 1 AS c2 FROM test;mysql>DESCRIBE t2;+-------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+------------+------+-----+---------+-------+ | c2 | bigint(21) | NO | | 0 | | +-------+------------+------+-----+---------+-------+这意味着
BIGINT UNSIGNED并非在所有情况下都能 100%使用。参见第 14.10 节,“类型转换函数和操作符”。This means thatBIGINT UNSIGNEDis not 100% usable in all contexts. See Section 14.10, “Cast Functions and Operators”.NO_ZERO_DATE模式影响服务器是否允许'0000-00-00'作为有效日期。其影响还取决于是否启用了严格 SQL 模式。TheNO_ZERO_DATEmode affects whether the server permits'0000-00-00'as a valid date. Its effect also depends on whether strict SQL mode is enabled.如果未启用此模式,
'0000-00-00'被允许,插入操作不会产生警告。If this mode is not enabled,'0000-00-00'is permitted and inserts produce no warning.如果启用此模式,
'0000-00-00'被允许,插入操作会产生警告。If this mode is enabled,'0000-00-00'is permitted and inserts produce a warning.如果同时启用此模式和严格模式,
'0000-00-00'不被允许,插入操作会产生错误,除非同时使用IGNORE。对于INSERT IGNORE和UPDATE IGNORE,'0000-00-00'被允许,插入操作会产生警告。If this mode and strict mode are enabled,'0000-00-00'is not permitted and inserts produce an error, unlessIGNOREis given as well. ForINSERT IGNOREandUPDATE IGNORE,'0000-00-00'is permitted and inserts produce a warning.
NO_ZERO_DATE已被弃用。NO_ZERO_DATE不属于严格模式的一部分,但应与严格模式一起使用,并且默认启用。如果启用了NO_ZERO_DATE而没有同时启用严格模式,或反之,则会出现警告。NO_ZERO_DATEis deprecated.NO_ZERO_DATEis not part of strict mode, but should be used in conjunction with strict mode and is enabled by default. A warning occurs ifNO_ZERO_DATEis enabled without also enabling strict mode or vice versa.由于
NO_ZERO_DATE已被弃用,因此您应预期它将在未来的 MySQL 版本中作为单独的模式名称被移除,其效果将包含在严格 SQL 模式的效果中。BecauseNO_ZERO_DATEis deprecated, you should expect it to be removed in a future MySQL release as a separate mode name and its effect included in the effects of strict SQL mode.NO_ZERO_IN_DATE模式影响服务器是否允许年份部分非零但月份或日期部分为 0 的日期。(此模式影响如'2010-00-01'或'2010-01-00'的日期,但不影响'0000-00-00'。要控制服务器是否允许'0000-00-00',请使用NO_ZERO_DATE模式。)NO_ZERO_IN_DATE的效果也取决于是否启用了严格 SQL 模式。TheNO_ZERO_IN_DATEmode affects whether the server permits dates in which the year part is nonzero but the month or day part is 0. (This mode affects dates such as'2010-00-01'or'2010-01-00', but not'0000-00-00'. To control whether the server permits'0000-00-00', use theNO_ZERO_DATEmode.) The effect ofNO_ZERO_IN_DATEalso depends on whether strict SQL mode is enabled.如果未启用此模式,则允许具有零部分的日期,并且插入不会产生警告。If this mode is not enabled, dates with zero parts are permitted and inserts produce no warning.
如果启用此模式,部分为零的日期将作为
'0000-00-00'插入,并产生警告。If this mode is enabled, dates with zero parts are inserted as'0000-00-00'and produce a warning.如果启用了此模式和严格模式,不允许插入部分为零的日期,插入将产生错误,除非同时指定
IGNORE。对于INSERT IGNORE和UPDATE IGNORE,部分为零的日期将作为'0000-00-00'插入,并产生警告。If this mode and strict mode are enabled, dates with zero parts are not permitted and inserts produce an error, unlessIGNOREis given as well. ForINSERT IGNOREandUPDATE IGNORE, dates with zero parts are inserted as'0000-00-00'and produce a warning.
NO_ZERO_IN_DATE已被弃用。NO_ZERO_IN_DATE并不是严格模式的一部分,但应与严格模式一起使用,并且默认启用。如果启用NO_ZERO_IN_DATE而未启用严格模式,或者反之,则会出现警告。NO_ZERO_IN_DATEis deprecated.NO_ZERO_IN_DATEis not part of strict mode, but should be used in conjunction with strict mode and is enabled by default. A warning occurs ifNO_ZERO_IN_DATEis enabled without also enabling strict mode or vice versa.因为
NO_ZERO_IN_DATE已被弃用,所以你应预期它将在未来的 MySQL 版本中作为单独模式名称被移除,其效果将包含在严格 SQL 模式的效果中。BecauseNO_ZERO_IN_DATEis deprecated, you should expect it to be removed in a future MySQL release as a separate mode name and its effect included in the effects of strict SQL mode.条件或
HAVING列表引用既未在ORDER BY子句中命名,也不在GROUP BY列的函数依赖关系(由其唯一确定的)中GROUP BY的非聚合列。Reject queries for which the select list,HAVINGcondition, orORDER BYlist refer to nonaggregated columns that are neither named in theGROUP BYclause nor are functionally dependent on (uniquely determined by)GROUP BYcolumns.MySQL 对标准 SQL 的扩展允许在
HAVING子句中引用选择列表中的别名表达式。无论是否启用了ONLY_FULL_GROUP_BY,HAVING子句都可以引用别名。A MySQL extension to standard SQL permits references in theHAVINGclause to aliased expressions in the select list. TheHAVINGclause can refer to aliases regardless of whetherONLY_FULL_GROUP_BYis enabled.有关更多讨论和示例,请参见 第 14.19.3 节,“MySQL 对 GROUP BY 的处理”。For additional discussion and examples, see Section 14.19.3, “MySQL Handling of GROUP BY”.
默认情况下,检索
CHAR列值时,会去掉尾随空格。如果启用了PAD_CHAR_TO_FULL_LENGTH,则不会进行去掉操作,检索到的CHAR值会填充到其完整长度。此模式不适用于VARCHAR列,后者在检索时会保留尾随空格。By default, trailing spaces are trimmed fromCHARcolumn values on retrieval. IfPAD_CHAR_TO_FULL_LENGTHis enabled, trimming does not occur and retrievedCHARvalues are padded to their full length. This mode does not apply toVARCHARcolumns, for which trailing spaces are retained on retrieval.NotePAD_CHAR_TO_FULL_LENGTH已被弃用。预计它将在未来的 MySQL 版本中被移除。PAD_CHAR_TO_FULL_LENGTHis deprecated. Expect it to be removed in a future version of MySQL.mysql>
CREATE TABLE t1 (c1 CHAR(10));Query OK, 0 rows affected (0.37 sec) mysql>INSERT INTO t1 (c1) VALUES('xy');Query OK, 1 row affected (0.01 sec) mysql>SET sql_mode = '';Query OK, 0 rows affected (0.00 sec) mysql>SELECT c1, CHAR_LENGTH(c1) FROM t1;+------+-----------------+ | c1 | CHAR_LENGTH(c1) | +------+-----------------+ | xy | 2 | +------+-----------------+ 1 row in set (0.00 sec) mysql>SET sql_mode = 'PAD_CHAR_TO_FULL_LENGTH';Query OK, 0 rows affected (0.00 sec) mysql>SELECT c1, CHAR_LENGTH(c1) FROM t1;+------------+-----------------+ | c1 | CHAR_LENGTH(c1) | +------------+-----------------+ | xy | 10 | +------------+-----------------+ 1 row in set (0.00 sec)将
||作为字符串连接操作符(与CONCAT()相同)处理,而不是作为OR的同义词。Treat||as a string concatenation operator (same asCONCAT()) rather than as a synonym forOR.将
REAL视为FLOAT的同义词。默认情况下,MySQL 将REAL视为DOUBLE的同义词。TreatREALas a synonym forFLOAT. By default, MySQL treatsREALas a synonym forDOUBLE.为所有存储引擎启用严格的 SQL 模式。无效的数据值将被拒绝。详情请参见 严格 SQL 模式。Enable strict SQL mode for all storage engines. Invalid data values are rejected. For details, see Strict SQL Mode.
为事务存储引擎启用严格的 SQL 模式,并在可能的情况下为非事务存储引擎启用。详情请参见 严格 SQL 模式。Enable strict SQL mode for transactional storage engines, and when possible for nontransactional storage engines. For details, see Strict SQL Mode.
控制在将带有小数秒部分的
TIME、DATE或TIMESTAMP值插入到具有相同类型但小数位数较少的列时是进行四舍五入还是截断。默认行为是使用四舍五入。如果启用此模式,则改为进行截断。以下语句序列说明了两者的区别:Control whether rounding or truncation occurs when inserting aTIME,DATE, orTIMESTAMPvalue with a fractional seconds part into a column having the same type but fewer fractional digits. The default behavior is to use rounding. If this mode is enabled, truncation occurs instead. The following sequence of statements illustrates the difference:CREATE TABLE t (id INT, tval TIME(1)); SET sql_mode=''; INSERT INTO t (id, tval) VALUES(1, 1.55); SET sql_mode='TIME_TRUNCATE_FRACTIONAL'; INSERT INTO t (id, tval) VALUES(2, 1.55);
生成的表格内容如下,其中第一个值已进行四舍五入,第二个值已进行截断:The resulting table contents look like this, where the first value has been subject to rounding and the second to truncation:
mysql>
SELECT id, tval FROM t ORDER BY id;+------+------------+ | id | tval | +------+------------+ | 1 | 00:00:01.6 | | 2 | 00:00:01.5 | +------+------------+另请参见 第 13.2.6 节,“时间值中的分数秒”。See also Section 13.2.6, “Fractional Seconds in Time Values”.
以下特殊模式作为前面列表中模式值组合的简写提供。The following special modes are provided as shorthand for combinations of mode values from the preceding list.
相当于
REAL_AS_FLOAT、PIPES_AS_CONCAT、ANSI_QUOTES、IGNORE_SPACE以及ONLY_FULL_GROUP_BY。Equivalent toREAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE, andONLY_FULL_GROUP_BY.ANSI模式还会导致服务器在以下情况下返回错误:当一个集合函数S与一个外部引用在外部查询中无法进行聚合时。这样的查询如下:S(outer_ref)ANSImode also causes the server to return an error for queries where a set functionSwith an outer referencecannot be aggregated in the outer query against which the outer reference has been resolved. This is such a query:S(outer_ref)SELECT * FROM t1 WHERE t1.a IN (SELECT MAX(t1.b) FROM t2 WHERE ...);
在这里,
MAX(t1.b)不能在外部查询中聚合,因为它出现在该查询的WHERE子句中。标准 SQL 要求在这种情况报错。如果未启用ANSI模式,服务器会将此类查询中的的处理方式与它解释S(outer_ref)时的方式相同。Here,S(const)MAX(t1.b)cannot aggregated in the outer query because it appears in theWHEREclause of that query. Standard SQL requires an error in this situation. IfANSImode is not enabled, the server treatsin such queries the same way that it would interpretS(outer_ref).S(const)参见 第 1.7 节,“MySQL 标准兼容性”。See Section 1.7, “MySQL Standards Compliance”.
TRADITIONAL相当于STRICT_TRANS_TABLES、STRICT_ALL_TABLES、NO_ZERO_IN_DATE、NO_ZERO_DATE、ERROR_FOR_DIVISION_BY_ZERO和NO_ENGINE_SUBSTITUTION。TRADITIONALis equivalent toSTRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO, andNO_ENGINE_SUBSTITUTION.
严格模式控制 MySQL 在处理数据更改语句(如 INSERT 或 UPDATE)中无效或缺失值的方式。一个值可能因多种原因无效。例如,它可能与列的数据类型不符,或者可能超出范围。当要插入的新行对于没有显式 DEFAULT 子句的非 NULL 列没有提供值时,该值就是缺失的。(对于 NULL 列,如果值缺失,则插入 NULL。)严格模式还会影响 DDL 语句,例如 CREATE TABLE。Strict mode controls how MySQL handles invalid or missing values
in data-change statements such as
INSERT or
UPDATE. A value can be invalid
for several reasons. For example, it might have the wrong data
type for the column, or it might be out of range. A value is
missing when a new row to be inserted does not contain a value
for a non-NULL column that has no explicit
DEFAULT clause in its definition. (For a
NULL column, NULL is
inserted if the value is missing.) Strict mode also affects DDL
statements such as CREATE TABLE.
如果未启用严格模式,MySQL 会为无效或缺失的值插入调整后的值,并生成警告(参见 第 15.7.7.42 节,“SHOW WARNINGS 语句”)。在严格模式下,你可以通过使用 INSERT IGNORE 或 UPDATE
IGNORE 来产生这种行为。If strict mode is not in effect, MySQL inserts adjusted values
for invalid or missing values and produces warnings (see
Section 15.7.7.42, “SHOW WARNINGS Statement”). In strict mode, you can
produce this behavior by using
INSERT IGNORE
or UPDATE
IGNORE.
对于诸如 SELECT 之类不更改数据的语句,在严格模式下,无效值会生成警告,而不是错误。For statements such as SELECT
that do not change data, invalid values generate a warning in
strict mode, not an error.
严格模式会对尝试创建超过最大键长度的键产生错误。当未启用严格模式时,这将导致警告,并将键截断到最大键长度。Strict mode produces an error for attempts to create a key that exceeds the maximum key length. When strict mode is not enabled, this results in a warning and truncation of the key to the maximum key length.
严格模式不会影响外键约束是否被检查。可以使用foreign_key_checks来进行检查。(参见第 7.1.8 节,“服务器系统变量”。)Strict mode does not affect whether foreign key constraints are
checked. foreign_key_checks can
be used for that. (See
Section 7.1.8, “Server System Variables”.)
如果启用了STRICT_ALL_TABLES或STRICT_TRANS_TABLES,则严格 SQL 模式生效,尽管这些模式的效果略有不同:Strict SQL mode is in effect if either
STRICT_ALL_TABLES or
STRICT_TRANS_TABLES is
enabled, although the effects of these modes differ somewhat:
对于事务表,当启用
STRICT_ALL_TABLES或STRICT_TRANS_TABLES时,如果数据更改语句中存在无效或缺失的值,将会发生错误。该语句会被中止并回滚。For transactional tables, an error occurs for invalid or missing values in a data-change statement when eitherSTRICT_ALL_TABLESorSTRICT_TRANS_TABLESis enabled. The statement is aborted and rolled back.对于非事务性表,如果错误值出现在要插入或更新的第一行中,无论哪种模式,行为都是相同的:该语句会中止,表保持不变。如果语句插入或修改多行且错误值出现在第二行或更后面的行中,则结果取决于启用了哪种严格模式:For nontransactional tables, the behavior is the same for either mode if the bad value occurs in the first row to be inserted or updated: The statement is aborted and the table remains unchanged. If the statement inserts or modifies multiple rows and the bad value occurs in the second or later row, the result depends on which strict mode is enabled:
对于
STRICT_ALL_TABLES,MySQL 会返回错误并忽略剩余的行。然而,由于之前的行已被插入或更新,结果是部分更新。为了避免这种情况,请使用单行语句,这样可以在不更改表的情况下中止操作。ForSTRICT_ALL_TABLES, MySQL returns an error and ignores the rest of the rows. However, because the earlier rows have been inserted or updated, the result is a partial update. To avoid this, use single-row statements, which can be aborted without changing the table.对于
STRICT_TRANS_TABLES,MySQL 会将无效值转换为该列的最接近有效值,并插入调整后的值。如果缺少某个值,MySQL 会插入该列数据类型的隐式默认值。在任何情况下,MySQL 都会生成警告而不是错误,并继续处理语句。隐式默认值的描述见 第 13.6 节,“数据类型默认值”。ForSTRICT_TRANS_TABLES, MySQL converts an invalid value to the closest valid value for the column and inserts the adjusted value. If a value is missing, MySQL inserts the implicit default value for the column data type. In either case, MySQL generates a warning rather than an error and continues processing the statement. Implicit defaults are described in Section 13.6, “Data Type Default Values”.
严格模式影响如下对零除、零日期以及日期中的零的处理:Strict mode affects handling of division by zero, zero dates, and zeros in dates as follows:
严格模式会影响除以零的处理,包括
MOD(:Strict mode affects handling of division by zero, which includesN,0)MOD(:N,0)对于数据变更操作(
INSERT,UPDATE):For data-change operations (INSERT,UPDATE):如果未启用严格模式,除以零会插入
NULL,并且不会产生警告。If strict mode is not enabled, division by zero insertsNULLand produces no warning.如果启用严格模式,除以零会产生错误,除非同时使用了
IGNORE。对于INSERT IGNORE和UPDATE IGNORE,除以零会插入NULL并产生警告。If strict mode is enabled, division by zero produces an error, unlessIGNOREis given as well. ForINSERT IGNOREandUPDATE IGNORE, division by zero insertsNULLand produces a warning.
对于
SELECT,除以零会返回NULL。启用严格模式也会产生警告。ForSELECT, division by zero returnsNULL. Enabling strict mode causes a warning to be produced as well.严格模式影响服务器是否允许
'0000-00-00'作为有效日期:Strict mode affects whether the server permits'0000-00-00'as a valid date:如果未启用严格模式,
'0000-00-00'被允许,并且插入时不会产生警告。If strict mode is not enabled,'0000-00-00'is permitted and inserts produce no warning.如果启用严格模式,
'0000-00-00'不被允许,插入时会产生错误,除非同时使用IGNORE。对于INSERT IGNORE和UPDATE IGNORE,'0000-00-00'被允许,并且插入时会产生警告。If strict mode is enabled,'0000-00-00'is not permitted and inserts produce an error, unlessIGNOREis given as well. ForINSERT IGNOREandUPDATE IGNORE,'0000-00-00'is permitted and inserts produce a warning.
严格模式会影响服务器是否允许年份部分非零但月份或日期部分为 0 的日期(例如
'2010-00-01'或'2010-01-00'):Strict mode affects whether the server permits dates in which the year part is nonzero but the month or day part is 0 (dates such as'2010-00-01'or'2010-01-00'):如果未启用严格模式,则允许具有零部分的日期,并且插入不会产生警告。If strict mode is not enabled, dates with zero parts are permitted and inserts produce no warning.
如果启用了严格模式,则不允许日期包含零部分,并且插入操作会产生错误,除非也使用了
IGNORE。对于INSERT IGNORE和UPDATE IGNORE,包含零部分的日期会插入为'0000-00-00'(在使用IGNORE时被视为有效)并产生警告。If strict mode is enabled, dates with zero parts are not permitted and inserts produce an error, unlessIGNOREis given as well. ForINSERT IGNOREandUPDATE IGNORE, dates with zero parts are inserted as'0000-00-00'(which is considered valid withIGNORE) and produce a warning.
有关有关 IGNORE 的严格模式的更多信息,请参阅 IGNORE 关键字与严格 SQL 模式的比较。For more information about strict mode with respect to
IGNORE, see
Comparison of the IGNORE Keyword and Strict SQL Mode.
严格模式影响在与 ERROR_FOR_DIVISION_BY_ZERO、NO_ZERO_DATE 和 NO_ZERO_IN_DATE 模式结合使用时,对除以零、零日期以及日期中的零的处理。Strict mode affects handling of division by zero, zero dates,
and zeros in dates in conjunction with the
ERROR_FOR_DIVISION_BY_ZERO,
NO_ZERO_DATE, and
NO_ZERO_IN_DATE modes.
本节比较了 IGNORE 关键字(将错误降级为警告)和严格 SQL 模式(将警告升级为错误)对语句执行的影响。它描述了它们影响的语句以及适用的错误类型。This section compares the effect on statement execution of the
IGNORE keyword (which downgrades errors to
warnings) and strict SQL mode (which upgrades warnings to
errors). It describes which statements they affect, and which
errors they apply to.
下表总结了在默认生成错误与警告时语句行为的对比。当默认生成错误的示例是向 NULL 列中插入 NOT
NULL。当默认生成警告的示例是向列中插入错误数据类型的值(例如将字符串 'abc' 插入整数列)。The following table presents a summary comparison of statement
behavior when the default is to produce an error versus a
warning. An example of when the default is to produce an error
is inserting a NULL into a NOT
NULL column. An example of when the default is to
produce a warning is inserting a value of the wrong data type
into a column (such as inserting the string
'abc' into an integer column).
| 操作模式Operational Mode | 当语句默认值为错误时When Statement Default is Error | 当语句默认值为警告时When Statement Default is Warning |
|---|---|---|
没有 IGNORE 或严格 SQL 模式Without IGNORE or strict SQL mode |
错误Error | 警告Warning |
使用 IGNOREWith IGNORE |
警告Warning | 警告(与不使用 IGNORE 或严格 SQL 模式相同)Warning (same as without IGNORE or strict SQL mode) |
| 使用严格 SQL 模式With strict SQL mode | 错误(与没有 IGNORE 或严格 SQL 模式相同)Error (same as without IGNORE or strict SQL mode) |
错误Error |
在使用 IGNORE 和严格 SQL 模式时With IGNORE and strict SQL mode |
警告Warning | 警告Warning |
从表中可以得出的一个结论是,当 IGNORE 关键字和严格 SQL 模式同时生效时,IGNORE 优先。这意味着,尽管 IGNORE 和严格 SQL 模式在错误处理上可以被认为有相反的效果,但它们一起使用时不会互相抵消。One conclusion to draw from the table is that when the
IGNORE keyword and strict SQL mode are both
in effect, IGNORE takes precedence. This
means that, although IGNORE and strict SQL
mode can be considered to have opposite effects on error
handling, they do not cancel when used together.
IGNORE 对语句执行的影响The Effect of IGNORE on Statement Execution
MySQL 中的若干语句支持可选的 IGNORE 关键字。该关键字会使服务器将某些类型的错误降级为警告。对于多行语句,将错误降级为警告可能使某一行得以处理。否则,IGNORE 会使语句跳过下一行而不是中止。(对于不可忽略的错误,无论是否使用 IGNORE 关键字,都会发生错误。)Several statements in MySQL support an optional
IGNORE keyword. This keyword causes the
server to downgrade certain types of errors and generate
warnings instead. For a multiple-row statement, downgrading an
error to a warning may enable a row to be processed. Otherwise,
IGNORE causes the statement to skip to the
next row instead of aborting. (For nonignorable errors, an error
occurs regardless of the IGNORE keyword.)
示例:如果表 t 有一个主键列 i,其中包含唯一值,尝试将相同的 i 值插入多行通常会产生重复键错误:Example: If the table t has a primary key
column i containing unique values, attempting
to insert the same value of i into multiple
rows normally produces a duplicate-key error:
mysql>CREATE TABLE t (i INT NOT NULL PRIMARY KEY);mysql>INSERT INTO t (i) VALUES(1),(1);ERROR 1062 (23000): Duplicate entry '1' for key 't.PRIMARY'
使用 IGNORE 时,包含重复键的行仍然不会被插入,但会产生警告,而不是错误:With IGNORE, the row containing the duplicate
key still is not inserted, but a warning occurs instead of an
error:
mysql>INSERT IGNORE INTO t (i) VALUES(1),(1);Query OK, 1 row affected, 1 warning (0.01 sec) Records: 2 Duplicates: 1 Warnings: 1 mysql>SHOW WARNINGS;+---------+------+-----------------------------------------+ | Level | Code | Message | +---------+------+-----------------------------------------+ | Warning | 1062 | Duplicate entry '1' for key 't.PRIMARY' | +---------+------+-----------------------------------------+ 1 row in set (0.00 sec)
示例:如果表 t2 有一个 NOT
NULL 列 id,在严格 SQL 模式下尝试插入 NULL 会产生错误:Example: If the table t2 has a NOT
NULL column id, attempting to
insert NULL produces an error in strict SQL
mode:
mysql>CREATE TABLE t2 (id INT NOT NULL);mysql>INSERT INTO t2 (id) VALUES(1),(NULL),(3);ERROR 1048 (23000): Column 'id' cannot be null mysql>SELECT * FROM t2;Empty set (0.00 sec)
如果 SQL 模式不是严格模式,IGNORE 会将 NULL 插入为该列的隐式默认值(在此情况下为 0),从而允许对该行进行处理而不会跳过它:If the SQL mode is not strict, IGNORE causes
the NULL to be inserted as the column
implicit default (0 in this case), which enables the row to be
handled without skipping it:
mysql>INSERT INTO t2 (id) VALUES(1),(NULL),(3);mysql>SELECT * FROM t2;+----+ | id | +----+ | 1 | | 0 | | 3 | +----+
这些语句支持 IGNORE 关键字:These statements support the IGNORE keyword:
CREATE TABLE ... SELECT:IGNORE不适用于CREATE TABLE或SELECT语句的部分,而是适用于向由SELECT产生的表中插入的行。在唯一键值上重复的行将被丢弃。CREATE TABLE ... SELECT:IGNOREdoes not apply to theCREATE TABLEorSELECTparts of the statement but to inserts into the table of rows produced by theSELECT. Rows that duplicate an existing row on a unique key value are discarded.DELETE:IGNORE会让 MySQL 在删除行的过程中忽略错误。DELETE:IGNOREcauses MySQL to ignore errors during the process of deleting rows.INSERT:使用IGNORE时,与唯一键值重复的行将被丢弃。设置为会导致数据转换错误的值的行将被设置为最接近的有效值。INSERT: WithIGNORE, rows that duplicate an existing row on a unique key value are discarded. Rows set to values that would cause data conversion errors are set to the closest valid values instead.对于分区表,如果没有找到匹配给定值的分区,
IGNORE会导致包含未匹配值的行的插入操作静默失败。 For partitioned tables where no partition matching a given value is found,IGNOREcauses the insert operation to fail silently for rows containing the unmatched value.LOAD DATA,LOAD XML:使用IGNORE时,与唯一键值重复的行将被丢弃。LOAD DATA,LOAD XML: WithIGNORE, rows that duplicate an existing row on a unique key value are discarded.UPDATE:使用IGNORE时,如果在唯一键值上发生重复键冲突的行将不会被更新。更新为可能导致数据转换错误的值的行将被更新为最接近的有效值。UPDATE: WithIGNORE, rows for which duplicate-key conflicts occur on a unique key value are not updated. Rows updated to values that would cause data conversion errors are updated to the closest valid values instead.
IGNORE 关键字适用于以下可忽略的错误:The IGNORE keyword applies to the following
ignorable errors:
严格 SQL 模式对语句执行的影响The Effect of Strict SQL Mode on Statement Execution
MySQL 服务器可以在不同的 SQL 模式下运行,并且可以根据 sql_mode 系统变量的值为不同客户端应用不同的模式。在 “strict” SQL 模式下,服务器会将某些警告升级为错误。The MySQL server can operate in different SQL modes, and can
apply these modes differently for different clients, depending
on the value of the sql_mode
system variable. In “strict” SQL mode, the server
upgrades certain warnings to errors.
例如,在非严格 SQL 模式下,将字符串 'abc' 插入整数列会导致该值转换为 0 并生成警告:For example, in non-strict SQL mode, inserting the string
'abc' into an integer column results in
conversion of the value to 0 and a warning:
mysql>SET sql_mode = '';Query OK, 0 rows affected (0.00 sec) mysql>INSERT INTO t (i) VALUES('abc');Query OK, 1 row affected, 1 warning (0.01 sec) mysql>SHOW WARNINGS;+---------+------+--------------------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------------------+ | Warning | 1366 | Incorrect integer value: 'abc' for column 'i' at row 1 | +---------+------+--------------------------------------------------------+ 1 row in set (0.00 sec)
在严格 SQL 模式下,无效值会被拒绝并显示错误:In strict SQL mode, the invalid value is rejected with an error:
mysql>SET sql_mode = 'STRICT_ALL_TABLES';Query OK, 0 rows affected (0.00 sec) mysql>INSERT INTO t (i) VALUES('abc');ERROR 1366 (HY000): Incorrect integer value: 'abc' for column 'i' at row 1
有关 sql_mode 系统变量的可能设置的更多信息,请参见 第 7.1.11 节,“服务器 SQL 模式”。For more information about possible settings of the
sql_mode system variable, see
Section 7.1.11, “Server SQL Modes”.
严格 SQL 模式适用于以下语句,在某些条件下,某个值可能超出范围,或向表中插入或删除无效行:Strict SQL mode applies to the following statements under conditions for which some value might be out of range or an invalid row is inserted into or deleted from a table:
在存储程序中,如果程序在严格模式下定义,则刚才列出的类型的单个语句将在严格 SQL 模式下执行。Within stored programs, individual statements of the types just listed execute in strict SQL mode if the program was defined while strict mode was in effect.
严格的 SQL 模式适用于以下错误,这些错误属于输入值无效或缺失的一类。值无效是指其数据类型与列不符或可能超出范围。值缺失是指要插入的新行中未包含 NOT
NULL 列的值,而该列在定义中没有明确的 DEFAULT 子句。Strict SQL mode applies to the following errors, which represent
a class of errors in which an input value is either invalid or
missing. A value is invalid if it has the wrong data type for
the column or might be out of range. A value is missing if a new
row to be inserted does not contain a value for a NOT
NULL column that has no explicit
DEFAULT clause in its definition.
ER_BAD_NULL_ERRORER_CUT_VALUE_GROUP_CONCATER_DATA_TOO_LONGER_DATETIME_FUNCTION_OVERFLOWER_DIVISION_BY_ZEROER_INVALID_ARGUMENT_FOR_LOGARITHMER_NO_DEFAULT_FOR_FIELDER_NO_DEFAULT_FOR_VIEW_FIELDER_TOO_LONG_KEYER_TRUNCATED_WRONG_VALUEER_TRUNCATED_WRONG_VALUE_FOR_FIELDER_WARN_DATA_OUT_OF_RANGEER_WARN_NULL_TO_NOTNULLER_WARN_TOO_FEW_RECORDSER_WRONG_ARGUMENTSER_WRONG_VALUE_FOR_TYPEWARN_DATA_TRUNCATED
由于持续的 MySQL 开发会定义新的错误,因此可能存在不在上述列表中的错误,这些错误适用于严格 SQL 模式。Because continued MySQL development defines new errors, there may be errors not in the preceding list to which strict SQL mode applies.