1071 - Specified key was too long; max key length is 767 bytes 博客分类: MySQL mysql1071
程序员文章站
2024-02-25 21:09:21
...
MySQL数据批量导入完毕后执行执行如下SQL(创建索引):
错误信息:
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,由此在建立索引的语句调正如下:
当然,不建议限制长度为89,最好比实际大一点(最大是255),还是要随机应变的!
MySQL慢查询分析案例
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,最好比实际大一点(最大是255),还是要随机应变的!
MySQL慢查询分析案例
推荐阅读
-
1071 - Specified key was too long; max key length is 767 bytes 博客分类: MySQL mysql1071
-
mysql建库时提示Specified key was too long max key length is 1000 bytes的问题的解决方法
-
MySQL:Specified key was too long; max key length is 767 bytes.
-
mysql建库时提示Specified key was too long max key length is 1000 bytes的问题的解决方法
-
MySQL错误“Specified key was too long; max key length is 1000 bytes”的解决办法
-
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
-
peewee.InternalError: (1071, '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
-
peewee.InternalError: (1071, 'Specified key was too long; max key length is 1000 bytes')