Documentation Home
MySQL 8.3 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.8Mb
PDF (A4) - 40.9Mb
Man Pages (TGZ) - 294.0Kb
Man Pages (Zip) - 409.0Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb
Excerpts from this Manual

12.3.7 国家字符集

标准SQL定义NCHARNATIONAL 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.3 将国家字符集解释为utf8mb3NATIONAL 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.