1071 -Specified key was too long; max key length is 767 bytes

1071 -Specified key was too long; max key length is 767 bytes

mysql导入同事发的sql文件报如下错误:1071 -Specified key was too long; max key length is 767 bytes
是因为数据库表采用utf8编码,其中varchar(255)的column进行了唯一键索引
而mysql默认情况下单个列的索引不能超过767位(不同版本可能存在差异)
于是utf8字符编码下,255*3 byte 超过限制
解决方法为:

(1) 使用innodb引擎;
(2) 启用innodb_large_prefix选项,将约束项扩展至3072byte;
(3) 重启MySQL服务;

my.cnf配置:

[mysqld]
default-storage-engine=INNODB
innodb_large_prefix=on
innodb_file_format=BARRACUDA

1071 -Specified key was too long; max key length is 767 bytes

参考:https://blog.csdn.net/qq_33210743/article/details/88739465