content_image/837990.jpg
CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL; 

The catch when converting from utf8mb3  to utf8mb4  is that the maximum length of a column or index key is unchanged in terms of bytes . Therefore, it is smaller in terms of characters  because the maximum length of a character is four bytes instead of three. For the CHAR , VARCHAR , and TEXT  data types, watch for these issues when converting your MySQL tables: 

•Check all definitions of utf8mb3  columns and make sure they do not exceed the maximum length for the storage engine. 

•Check all indexes on utf8mb3  columns and make sure they do not exceed the maximum length for the storage engine. Sometimes the maximum can change due to storage engine enhancements. 

If the preceding conditions apply, you must either reduce the defined length of columns or indexes, or continue to use utf8mb3  rather than utf8mb4 . 

Here are some examples where structural changes may be needed: 

•A TINYTEXT  column can hold up to 255 bytes, so it can hold up to 85 3-byte or 63 4-byte characters. Suppose that you have a TINYTEXT  column that uses utf8mb3  but must be able to contain more than 63 characters. You cannot convert it to utf8mb4  unless you also change the data type to a longer type such as TEXT . 

Similarly, a very long VARCHAR  column may need to be changed to one of the longer TEXT  types if you want to convert it from utf8mb3  to utf8mb4 . 

• InnoDB  has a maximum index length of 767 bytes for tables that use COMPACT  or REDUNDANT  row format, so for utf8mb3  or utf8mb4  columns, you can index a maximum of 255 or 191 characters, respectively. If you currently have utf8mb3  columns with indexes longer than 191 characters, you must index a smaller number of characters. 

In an InnoDB  table that uses COMPACT  or REDUNDANT  row format, these column and index definitions are legal: 

col1 VARCHAR(500) CHARACTER SET utf8, INDEX (col1(255)) 

To use utf8mb4  instead, the index must be smaller: 

col1 VARCHAR(500) CHARACTER SET utf8mb4, INDEX (col1(191)) 

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

## Note 

For InnoDB  tables that use COMPRESSED  or DYNAMIC  row format, index key prefixes longer than 767 bytes (up to 3072 bytes) are permitted. Tables created with these row formats enable you to index a maximum of 1024 or 768 characters for utf8mb3  or utf8mb4  columns, respectively. For related information, see Section 15.22, “InnoDB Limits” , and DYNAMIC Row Format. 

The preceding types of changes are most likely to be required only if you have very long columns or indexes. Otherwise, you should be able to convert your tables from utf8mb3  to utf8mb4  without problems, using ALTER TABLE  as described previously. 

The following items summarize other potential incompatibilities: 

• SET NAMES ’utf8mb4’  causes use of the 4-byte character set for connection character sets. As long as no 4-byte characters are sent from the server, there should be no problems. Otherwise, applications that expect to receive a maximum of three bytes per character may have problems. Conversely, applications that expect to send 4-byte characters must ensure that the server understands them. 

