utf32 字符集是固定长度的(像 ucs2,不像 utf16)。utf32 每个字符使用 32 位,不像 ucs2(每个字符使用 16 位),也不像 utf16(有些字符使用 16 位,有些字符使用 32 位)。The utf32 character set is fixed length (like
ucs2 and unlike utf16).
utf32 uses 32 bits for every character,
unlike ucs2 (which uses 16 bits for every
character), and unlike utf16 (which uses 16
bits for some characters and 32 bits for others).
utf32 占用的空间是 ucs2 的两倍,并且比 utf16 占用更多空间,但 utf32 和 ucs2 有相同的优势,即存储是可预测的:utf32 所需的字节数等于字符数乘以 4。此外,与 utf16 不同,utf32 没有任何编码技巧,因此存储的值等于代码值。utf32 takes twice as much space as
ucs2 and more space than
utf16, but utf32 has the
same advantage as ucs2 that it is predictable
for storage: The required number of bytes for
utf32 equals the number of characters times
4. Also, unlike utf16, there are no tricks
for encoding in utf32, so the stored value
equals the code value.
为了演示后者优势的用途,这里有一个示例,展示如何根据 utf32 代码值确定 utf8mb4 的值:To demonstrate how the latter advantage is useful, here is an
example that shows how to determine a utf8mb4
value given the utf32 code value:
/* Assume code value = 100cc LINEAR B WHEELED CHARIOT */
CREATE TABLE tmp (utf32_col CHAR(1) CHARACTER SET utf32,
utf8mb4_col CHAR(1) CHARACTER SET utf8mb4);
INSERT INTO tmp VALUES (0x000100cc,NULL);
UPDATE tmp SET utf8mb4_col = utf32_col;
SELECT HEX(utf32_col),HEX(utf8mb4_col) FROM tmp;
MySQL 对未分配的 Unicode 字符或私有使用区字符的添加非常宽容。事实上,对于 utf32 来说,只有一项有效性检查:代码值不得大于 0x10ffff。例如,这是非法的:MySQL is very forgiving about additions of unassigned Unicode
characters or private-use-area characters. There is in fact only
one validity check for utf32: No code value
may be greater than 0x10ffff. For example,
this is illegal:
INSERT INTO t (utf32_column) VALUES (0x110000); /* illegal */