content_image/850992.jpg content_image/850993.jpg
<img src='content_image/850992.jpg'>

The utf8mb3  and utf8mb4  character sets differ as follows: 

## Note 

This discussion focuses primarily on converting between utf8mb3  and utf8mb4 , but similar principles apply to converting between the ucs2  character set and character sets such as utf16  or utf32 . 

• utf8mb3  supports only characters in the Basic Multilingual Plane (BMP). utf8mb4  additionally supports supplementary characters that lie outside the BMP. 

• utf8mb3  uses a maximum of three bytes per character. utf8mb4  uses a maximum of four bytes per character. 

<img src='content_image/850993.jpg'>

## Note 

This discussion refers to the utf8mb3  and utf8mb4  character set names to be explicit about referring to 3-byte and 4-byte UTF-8 character set data. The exception is that in table definitions, utf8  is used because MySQL converts instances of utf8mb3  specified in such definitions to utf8 , which is an alias for utf8mb3 . 

One advantage of converting from utf8mb3  to utf8mb4  is that this enables applications to use supplementary characters. One tradeoff is that this may increase data storage space requirements. 

In terms of table content, conversion from utf8mb3  to utf8mb4  presents no problems: 

•For a BMP character, utf8mb4  and utf8mb3  have identical storage characteristics: same code values, same encoding, same length. 

•For a supplementary character, utf8mb4  requires four bytes to store it, whereas utf8mb3  cannot store the character at all. When converting utf8mb3  columns to utf8mb4 , you need not worry about converting supplementary characters because there are none. 

In terms of table structure, these are the primary potential incompatibilities: 

•For the variable-length character data types ( VARCHAR  and the TEXT  types), the maximum permitted length in characters is less for utf8mb4  columns than for utf8mb3  columns. 

•For all character data types ( CHAR , VARCHAR , and the TEXT  types), the maximum number of characters that can be indexed is less for utf8mb4  columns than for utf8mb3  columns. 

Consequently, to convert tables from utf8mb3  to utf8mb4 , it may be necessary to change some column or index definitions. 

Tables can be converted from utf8mb3  to utf8mb4  by using ALTER TABLE . Suppose that a table has this definition: 

CREATE TABLE t1 ( col1 CHAR(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, col2 CHAR(10) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ) CHARACTER SET utf8; 

The following statement converts t1  to use utf8mb4 : 

ALTER TABLE t1 DEFAULT CHARACTER SET utf8mb4, MODIFY col1 CHAR(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, MODIFY col2 CHAR(10) 

