问题现象:
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
建表结构:
create table xx (
id bigint not null auto_increment,
col_1 bigint not null,
col_2 varchar(255) not null,
primary key (id),
unique uniq_xx (col_1,col_2))
engine=innodb DEFAULT CHARSET=utf8mb4;原因:
MySQL默认单列索引不能超过767字节,但是utf8编码255*3超过了这个限制。
解决:
打开innodb选项innodb_large_prefix,将这个限制扩充至3072字节。
参考:
https://dev.mysql.com/doc/refman/5.6/en/innodb-parameters.html#sysvar_innodb_large_prefix
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26950862/viewspace-3153742/ ,如需转载,请注明出处,否则将追究法律责任。