Specified key '%s' was too long; max key length is 767 bytes.

出现这个错误是在创建索引的时候,原因所选字段的长度超出了可以创建索引的最大长度,InnoDB是767字节,但是有时候明明所选字段的长度很小比如 255 明显比这个小 为什么会报错呢,原来 所选字段当时UTF8编码的时候需要乘以3 UTF8mb4的时候需要乘以4,MySQL reserves 3 bytes per UTF8 character 官网地址mysql

Paste_Image.png

让然也可以修改限制从767 bytes (up to 3072 bytes). 在my.cnf文件中

[mysqld]
innodb_file_format=barracuda
innodb_file_per_table=1
innodb_large_prefix=1
init_connect='SET collation_connection = utf8mb4_unicode_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4collation-server=utf8mb4_unicode_ci

主要是这两项
innodb_file_format=barracuda
and innodb_file_per_table=true
.

767 up to 3072
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容