8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / A MySQL 8.4 Frequently Asked Questions / A.3 MySQL 8.4 FAQ: Server SQL Mode
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 77%

A.3 MySQL 8.4 常见问题解答:服务器 SQL 模式A.3 MySQL 8.4 FAQ: Server SQL Mode

A.3.1. 服务器 SQL 模式是什么? A.3.1. What are server SQL modes?
A.3.2. 有多少种服务器 SQL 模式? A.3.2. How many server SQL modes are there?
A.3.3. 如何确定服务器 SQL 模式? A.3.3. How do you determine the server SQL mode?
A.3.4. 模式是否依赖于数据库或连接? A.3.4. Is the mode dependent on the database or connection?
A.3.5. 严格模式的规则可以扩展吗?A.3.5. Can the rules for strict mode be extended?
A.3.6. 严格模式会影响性能吗?A.3.6. Does strict mode impact performance?
A.3.7. 安装 MySQL 8.4 时,默认的服务器 SQL 模式是什么?A.3.7. What is the default server SQL mode when MySQL 8.4 is installed?

A.3.1.

什么是服务器 SQL 模式?What are server SQL modes?

服务器 SQL 模式定义了 MySQL 应该支持的 SQL 语法以及它应该执行的数据验证检查类型。这使得在不同环境中使用 MySQL 以及与其他数据库服务器一起使用 MySQL 变得更加容易。MySQL 服务器会针对不同的客户端单独应用这些模式。更多信息,请参见 第 7.1.11 节,“服务器 SQL 模式”。Server SQL modes define what SQL syntax MySQL should support and what kind of data validation checks it should perform. This makes it easier to use MySQL in different environments and to use MySQL together with other database servers. The MySQL Server apply these modes individually to different clients. For more information, see Section 7.1.11, “Server SQL Modes”.

A.3.2.

服务器 SQL 模式有多少种?How many server SQL modes are there?

每种模式可以独立开关。完整的可用模式列表,请参见 第 7.1.11 节,“服务器 SQL 模式”。Each mode can be independently switched on and off. See Section 7.1.11, “Server SQL Modes”, for a complete list of available modes.

A.3.3.

如何确定服务器 SQL 模式?How do you determine the server SQL mode?

您可以使用 --sql-mode 选项来设置默认 SQL 模式(用于 mysqld 启动)。使用语句 SET [GLOBAL|SESSION] sql_mode='modes',您可以在连接内更改设置,无论是仅对该连接本地生效,还是全局生效。您可以通过执行 SELECT @@sql_mode 语句来检索当前模式。You can set the default SQL mode (for mysqld startup) with the --sql-mode option. Using the statement SET [GLOBAL|SESSION] sql_mode='modes', you can change the settings from within a connection, either locally to the connection, or to take effect globally. You can retrieve the current mode by issuing a SELECT @@sql_mode statement.

A.3.4.

模式是否依赖于数据库或连接?Is the mode dependent on the database or connection?

模式不与特定的数据库关联。模式可以在会话(连接)本地设置,或为服务器全局设置。您可以使用 SET [GLOBAL|SESSION] sql_mode='modes' 来更改这些设置。A mode is not linked to a particular database. Modes can be set locally to the session (connection), or globally for the server. you can change these settings using SET [GLOBAL|SESSION] sql_mode='modes'.

A.3.5.

严格模式的规则可以扩展吗?Can the rules for strict mode be extended?

当我们提到严格模式时,我们的意思是至少启用了以下模式之一:TRADITIONAL、STRICT_TRANS_TABLES或STRICT_ALL_TABLES。选项可以组合,因此您可以在一个模式上增加限制。有关更多信息,请参见第 7.1.11 节,“服务器 SQL 模式”。When we refer to strict mode, we mean a mode where at least one of the modes TRADITIONAL, STRICT_TRANS_TABLES, or STRICT_ALL_TABLES is enabled. Options can be combined, so you can add restrictions to a mode. See Section 7.1.11, “Server SQL Modes”, for more information.

A.3.6.

严格模式会影响性能吗?Does strict mode impact performance?

某些设置所需的输入数据的严格验证比不进行验证需要更多的时间。虽然性能影响不是很大,但如果您不需要这种验证(可能您的应用程序已经处理了所有这些),那么 MySQL 允许您选择禁用严格模式。但是,如果您确实需要,它可以提供这种验证。The intensive validation of input data that some settings requires more time than if the validation is not done. While the performance impact is not that great, if you do not require such validation (perhaps your application already handles all of this), then MySQL gives you the option of leaving strict mode disabled. However, if you do require it, strict mode can provide such validation.

A.3.7.

安装 MySQL 8.4 时,默认的服务器 SQL 模式是什么?What is the default server SQL mode when MySQL 8.4 is installed?

MySQL 8.0 中的默认 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.0 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.

有关所有可用模式和默认 MySQL 行为的信息,请参见 第 7.1.11 节,“服务器 SQL 模式”。For information about all available modes and default MySQL behavior, see Section 7.1.11, “Server SQL Modes”.