MySQL错误“Specified key was too long; max key length is 1000 bytes”

Posted Forward1990

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL错误“Specified key was too long; max key length is 1000 bytes”相关的知识,希望对你有一定的参考价值。

建立索引时,数据库计算key的长度是累加所有Index用到的字段的char长度后再按下面比例乘起来不能超过限定的key长度1000: 
latin1 = 1 byte = 1 character 
uft8 = 3 byte = 1 character 
gbk = 2 byte = 1 character 
举例能看得更明白些,以GBK为例: 
CREATE UNIQUE INDEX `unique_record` ON reports (`report_name`, `report_client`, `report_city`); 
其中report_name varchar(200), report_client varchar(200), report_city varchar(200) 
(200 + 200 +200) * 2 = 1200 > 1000,所有就会报1071错误,只要将report_city改为varchar(100)那么索引就能成功建立。 
如果表是UTF8字符集,那索引还是建立不了。









以上是关于MySQL错误“Specified key was too long; max key length is 1000 bytes”的主要内容,如果未能解决你的问题,请参考以下文章

ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

Mysql执行脚本Specified key was too long; max key length is 767 bytes问题解决

Mysql执行脚本Specified key was too long; max key length is 767 bytes问题解决

MySQL 提示:MySql Specified key was too long; max key length is **** bytes

MySQL双字符主键过长 Specified key was too long; max key length is 767 bytes