Rechercher dans le manuel MySQL
10.9.5 The utf16 Character Set (UTF-16 Unicode Encoding)
The utf16
character set is the
ucs2
character set with an extension that
enables encoding of supplementary characters:
For a BMP character,
utf16
anducs2
have identical storage characteristics: same code values, same encoding, same length.For a supplementary character,
utf16
has a special sequence for representing the character using 32 bits. This is called the “surrogate” mechanism: For a number greater than0xffff
, take 10 bits and add them to0xd800
and put them in the first 16-bit word, take 10 more bits and add them to0xdc00
and put them in the next 16-bit word. Consequently, all supplementary characters require 32 bits, where the first 16 bits are a number between0xd800
and0xdbff
, and the last 16 bits are a number between0xdc00
and0xdfff
. Examples are in Section 15.5 Surrogates Area of the Unicode 4.0 document.
Because utf16
supports surrogates and
ucs2
does not, there is a validity check that
applies only in utf16
: You cannot insert a
top surrogate without a bottom surrogate, or vice versa. For
example:
There is no validity check for characters that are technically
valid but are not true Unicode (that is, characters that Unicode
considers to be “unassigned code points” or
“private use” characters or even
“illegals” like 0xffff
). For
example, since U+F8FF
is the Apple Logo, this
is legal:
Such characters cannot be expected to mean the same thing to everyone.
Because MySQL must allow for the worst case (that one character
requires four bytes) the maximum length of a
utf16
column or index is only half of the
maximum length for a ucs2
column or index.
For example, the maximum length of a MEMORY
table index key is 3072 bytes, so these statements create tables
with the longest permitted indexes for ucs2
and utf16
columns:
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-charset-unicode-utf16.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.