How can I alter an indexed varchar(255) from utf8 to utf8mb4 and still stay under the 767 max key length?

前端 未结 2 442
情歌与酒
情歌与酒 2021-01-19 13:23

I have an mysql column that needs to support emoji, and that means converting a utf8 column into a utf8mb4. But my varchar(255) won\'t fit, so long as the column is indexed

2条回答
  •  醉梦人生
    2021-01-19 14:21

    I ended up removing the index.

    If performance is negatively impacted I may add a second indexed column that only contains the first n characters (up to 191, but likely just 10-20 or so) of the current column.

    The 191 character limit is due to the maximum key length of 767 bytes. For a 4 byte character, this means a max of 191 characters (floor(767/4) = 191).

提交回复
热议问题