1071 - Specified key was too long; max key length is 767 bytes, Time: 0.001000s

数据如下

CREATE TABLE `user_innodb` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `gender` tinyint(1) DEFAULT NULL,
  `phone` varchar(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `comidx_name_phone` (`name`,`phone`)
) ENGINE=InnoDB AUTO_INCREMENT=1000001 DEFAULT CHARSET=utf8mb4;

运行如下错误:
1071 - Specified key was too long; max key length is 767 bytes, Time: 0.001000s
错误原因:
这个“ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes”错误是指超出索引字节的限制,并不是指字段长度限制。在官方文档“Limits on InnoDB Tables”有关于这方面的介绍、描述(详情请见参考资料):

解决方案

启用系统变量innodb_large_prefix
注意:光有这个系统变量开启是不够的。必须满足下面几个条件:

1: 系统变量innodb_large_prefix为ON

2: 系统变量innodb_file_format为Barracuda

3: ROW_FORMAT为DYNAMIC或COMPRESSED

在这里插入图片描述

set global innodb_large_prefix=on;

在这里插入图片描述
在这里插入图片描述

成功解决

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/OnlyoneFrist/article/details/105666240
今日推荐