本节介绍 MySQL 与 ANSI/ISO SQL 标准的关系。 MySQL Server 对 SQL 标准有许多扩展,在这里您可以了解它们是什么以及如何使用它们。您还可以找到有关 MySQL Server 缺少的功能以及如何解决某些差异的信息。This section describes how MySQL relates to the ANSI/ISO SQL standards. MySQL Server has many extensions to the SQL standard, and here you can find out what they are and how to use them. You can also find information about functionality missing from MySQL Server, and how to work around some of the differences.
SQL 标准自 1986 年以来一直在不断发展,并且存在多个版本。本手册中,“SQL-92”指 1992 年发布的标准。 “SQL:1999”、“SQL:2003”、“SQL:2008”和“SQL:2011”是指相应年份发布的标准版本,最后一个是最新版本。我们使用短语“SQL 标准”或“标准 SQL” 随时表示 SQL 标准的当前版本。The SQL standard has been evolving since 1986 and several versions exist. In this manual, “SQL-92” refers to the standard released in 1992. “SQL:1999”, “SQL:2003”, “SQL:2008”, and “SQL:2011” refer to the versions of the standard released in the corresponding years, with the last being the most recent version. We use the phrase “the SQL standard” or “standard SQL” to mean the current version of the SQL Standard at any time.
我们对该产品的主要目标之一是继续努力遵守 SQL 标准,但不牺牲速度或可靠性。如果添加 SQL 扩展或对非 SQL 功能的支持能够大大提高 MySQL Server 对于我们大部分用户群的可用性,我们并不害怕。 HANDLER 接口就是此策略的一个示例。请参阅第 15.2.5 节“HANDLER 语句”。One of our main goals with the product is to continue to work
toward compliance with the SQL standard, but without sacrificing
speed or reliability. We are not afraid to add extensions to SQL
or support for non-SQL features if this greatly increases the
usability of MySQL Server for a large segment of our user base.
The HANDLER interface is an example
of this strategy. See Section 15.2.5, “HANDLER Statement”.
我们继续支持事务性和非事务性数据库,以满足任务关键型 24/7 使用和大量 Web 或日志记录使用。We continue to support transactional and nontransactional databases to satisfy both mission-critical 24/7 usage and heavy Web or logging usage.
MySQL Server 最初设计用于处理中型数据库(10-1 亿行,或大约在小型计算机系统上每表 100MB。如今,MySQL 服务器可处理 TB 级数据库。MySQL Server was originally designed to work with medium-sized databases (10-100 million rows, or about 100MB per table) on small computer systems. Today MySQL Server handles terabyte-sized databases.
尽管 MySQL 复制功能提供了重要的功能,但我们的目标并不是实时支持。We are not targeting real-time support, although MySQL replication capabilities offer significant functionality.
MySQL 支持 ODBC 级别 0 到 3.51。MySQL supports ODBC levels 0 to 3.51.
MySQL 使用 NDBCLUSTER 存储引擎。请参阅第 25 章,MySQL NDB Cluster 8.4。MySQL supports high-availability database clustering using the
NDBCLUSTER storage engine. See
Chapter 25, MySQL NDB Cluster 8.4.
我们实现了支持大多数 W3C XPath 标准的 XML 功能。请参阅第 14.11 节“XML 函数”。We implement XML functionality which supports most of the W3C XPath standard. See Section 14.11, “XML Functions”.
MySQL 支持由 RFC 7159 定义并基于 ECMAScript 标准 (ECMA-262) 的本机 JSON 数据类型。请参阅第 13.5 节“JSON 数据类型”。 MySQL 还实现了 SQL:2016 标准预发布草案中指定的 SQL/JSON 函数的子集;有关详细信息,请参阅第 14.17 节“JSON 函数”。MySQL supports a native JSON data type as defined by RFC 7159, and based on the ECMAScript standard (ECMA-262). See Section 13.5, “The JSON Data Type”. MySQL also implements a subset of the SQL/JSON functions specified by a pre-publication draft of the SQL:2016 standard; see Section 14.17, “JSON Functions”, for more information.
选择 SQL 模式Selecting SQL Modes
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.
有关设置 SQL 模式的详细信息,请参阅第 7.1.11 节“服务器 SQL 模式”。For more information on setting the SQL mode, see Section 7.1.11, “Server SQL Modes”.
在 ANSI 中运行 MySQL 模式Running MySQL in ANSI Mode
要在 ANSI 模式下运行 MySQL Server,请使用 --ansi 选项启动 mysqld。以 ANSI 模式运行服务器与使用以下选项启动服务器相同:To run MySQL Server in ANSI mode, start mysqld
with the --ansi option. Running the
server in ANSI mode is the same as starting it with the following
options:
--transaction-isolation=SERIALIZABLE --sql-mode=ANSI
要在运行时达到相同的效果,请执行以下两条语句:To achieve the same effect at runtime, execute these two statements:
SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE; SET GLOBAL sql_mode = 'ANSI';
您可以看到,将 sql_mode 系统变量设置为 'ANSI' 会启用与 ANSI 相关的所有 SQL 模式选项模式如下:You can see that setting the
sql_mode system variable to
'ANSI' enables all SQL mode options that are
relevant for ANSI mode as follows:
mysql>SET GLOBAL sql_mode='ANSI';mysql>SELECT @@GLOBAL.sql_mode;-> 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ANSI'
使用 --ansi 在 ANSI 模式下运行服务器与将 SQL 模式设置为 'ANSI' 不太一样,因为 --ansi 选项还设置事务隔离级别。Running the server in ANSI mode with
--ansi is not quite the same as
setting the SQL mode to 'ANSI' because the
--ansi option also sets the
transaction isolation level.
请参阅第 7.1.7 节“服务器命令选项”。See Section 7.1.7, “Server Command Options”.