标准 SQL 定义了 NCHAR 或 NATIONAL CHAR 作为指示 CHAR 列应使用某个预定义字符集的方式。MySQL 使用 utf8 作为该预定义字符集。例如,这些数据类型声明是等效的:Standard SQL defines NCHAR or
NATIONAL CHAR as a way to
indicate that a CHAR column
should use some predefined character set. MySQL uses
utf8 as this predefined character set. For
example, these data type declarations are equivalent:
CHAR(10) CHARACTER SET utf8 NATIONAL CHARACTER(10) NCHAR(10)
像这些一样:As are these:
VARCHAR(10) CHARACTER SET utf8 NATIONAL VARCHAR(10) NVARCHAR(10) NCHAR VARCHAR(10) NATIONAL CHARACTER VARYING(10) NATIONAL CHAR VARYING(10)
您可以使用 N'(或 literal'n')来创建国家字符集中的字符串。这些语句是等价的:You can use
literal'N' (or
literal'n') to
create a string in the national character set. These statements
are equivalent:literal'
SELECT N'some text'; SELECT n'some text'; SELECT _utf8'some text';
MySQL 8.4 将国家字符集解释为 utf8mb3,该字符集现在已被弃用。因此,使用 NATIONAL CHARACTER 或其同义词之一来定义数据库、表或列的字符集时,会出现类似如下的警告:MySQL 8.4 interprets the national character set as
utf8mb3, which is now deprecated. Thus, using
NATIONAL CHARACTER or one of its synonyms to
define the character set for a database, table, or column raises
a warning similar to this one:
NATIONAL/NCHAR/NVARCHAR implies the character set UTF8MB3, which will be replaced by UTF8MB4 in a future release. Please consider using CHAR(x) CHARACTER SET UTF8MB4 in order to be unambiguous.