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

MySQL数据批量导入完毕后执行执行如下SQL(创建索引):
CREATE INDEX `recipe_form_index` USING BTREE ON `audit_form`(`zone_id`,`type`,`event_nos`)


错误信息:
1071 - Specified key was too long; max key length is 767 bytes

原因是event_nos的字段值长度允许最大是1000,而在库中实际存储最大长度,查询如下:
mysql> select length(event_nos) from `audit_form` order by CHAR_LENGTH(`event_nos`) DESC limit 1;
+-------------------+
| length(event_nos) |
+-------------------+
|               89 |
+-------------------+
1 row in set

mysql>


由此可见最大长度是89,由此在建立索引的语句调正如下:
CREATE INDEX `recipe_form_index` USING BTREE ON `audit_form`(`zone_id`,`type`,`event_nos`(89));


当然,不建议限制长度为89,最好比实际大一点,还是要随机应变的!

你可能感兴趣的:(mysql,1071)