建立varchar字段的索引时,提示Specified key was too long; max key length is 767 bytes
2016-08-05 11:00
363 查看
字段设置unique索引的时候,是Mysql的字段设置的太长了,把相关字段的长度改了一下就好了。
建立索引时,数据库计算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错误,只要将 你的字段 改为varchar(100)那么索引就能成功建立。
建立索引时,数据库计算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错误,只要将 你的字段 改为varchar(100)那么索引就能成功建立。
相关文章推荐
- 索引长度过长 ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
- Hive 创建表提示"Specified key was too long; max key length is 767 bytes"解决办法
- Hive集成Mysql作为元数据时,提示错误:Specified key was too long; max key length is 767 bytes
- Hive集成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: ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
- MySQL中ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes错误的处理
- hive的Specified key was too long; max key length is 767 bytes问题解决
- hive的Specified key was too long; max key length is 767 bytes问题解决
- hive的Specified key was too long; max key length is 767 bytes问题解决
- mysql [Err] 1071 - Specified key was too long; max key length is 767 bytes
- Hive 创建表报"Specified key was too long; max key length is 767 bytes" 错误
- OPENFIRE+MYSQL5.6安装中遇见Specified key was too long; max key length is 767 bytes openfire处理办法
- MySQL:Specified key was too long; max key length is 767 bytes
- mysql建库时提示Specified key was too long max key length is 1000 bytes的问题的解决方法
- 解决com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Specified key was too long; max key length is 767 bytes异常
- Specified key was too long; max key length is 767 bytes
- MySQLSyntaxErrorException: Specified key was too long; max key length is 767 bytes
- MySQL: ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
- hive的Specified key was too long; max key length is 767 bytes问题解决