最近在一个varcher(255)的字段增加普通索引的时候发现后面自动追加了191,这是什么原因呢?
官方文档是这样说的(https://dev.mysql.com/doc/refman/5.7/en/charset-unicode-conversion.html):
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.
也就是说单个索引最大长度是767字节,用的编码是utf8mb4,则可以存储191个字符(767/4 约等于 191),
字段长度超出了索引最大值能后MySQL 默认在普通索引追加了191。