Documentation Home
MySQL 8.4 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 39.8Mb
PDF (A4) - 39.9Mb
Man Pages (TGZ) - 257.9Kb
Man Pages (Zip) - 364.9Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb


12.3.7 国家字符集

标准SQL定义NCHAR NATIONAL CHAR作为指示一个CHAR列应该使用某个预定义字符集的方式。MySQL使用utf8作为这个预定义字符集。例如,这些数据类型声明是等价的:

CHAR(10) CHARACTER SET utf8
NATIONAL CHARACTER(10)
NCHAR(10)

这些也是等价的:

VARCHAR(10) CHARACTER SET utf8
NATIONAL VARCHAR(10)
NVARCHAR(10)
NCHAR VARCHAR(10)
NATIONAL CHARACTER VARYING(10)
NATIONAL CHAR VARYING(10)

您可以使用N'literal'(或n'literal')来创建一个国家字符集的字符串。这些语句是等价的:

SELECT N'some text';
SELECT n'some text';
SELECT _utf8'some text';

MySQL 8.4将国家字符集解释为utf8mb3,现在已经弃用了。因此,使用NATIONAL CHARACTER或其同义词来定义数据库、表或列的字符集会出现类似于以下警告:

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.