ITPub博客

首页 > 数据库 > > MySQL创建唯一复合索引时出现ERROR 1071(42000)

MySQL创建唯一复合索引时出现ERROR 1071(42000)

作者:362931297 时间:2019-09-05 19:56:19 0 删除 编辑

问题现象:

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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-09-19

  • 博文量
    6
  • 访问量
    34