1071 - Specified key was too long; max key length is 1000 bytes
时间: 2023-11-14 11:08:34 浏览: 135
这个错误通常是由于 MySQL 版本过低导致的,因为在 MySQL 5.7.7 版本之后,InnoDB 引擎默认使用了 utf8mb4 字符集,而 utf8mb4 字符集下一个字符最多占用 4 个字节,因此索引长度超过了 1000 字节的限制。解决方法是将表的字符集改为 utf8 或者将 MySQL 升级到 5.7.7 及以上版本。
相关问题
[Err] 1071 - Specified key was too long; max key length is 1000 bytes
1071 - Specified key was too long; max key length is 1000 bytes 是一个错误信息,表示指定的键太长,最大键长度为1000个字节。这个错误通常发生在数据库中创建唯一键时,当键的长度超过了数据库所允许的最大长度时会出现该错误。引用提到了这个错误信息,并且指出是在尝试为`users`表添加一个唯一键(`users_username_unique`)时出现的。MySQL 5.7版本中,varchar的长度是根据字符数来计算的,一个字母或汉字都算作一个字符。因此,当键的长度超过1000个字节时,就会出现这个错误。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [[Err] 1071 - Specified key was too long; max key length is 767 bytes](https://blog.csdn.net/woshiwozzl/article/details/107491729)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [创建索引时,解决1071 Specified key was too long; max key length is 1000 bytes错误信息](https://blog.csdn.net/alpeace/article/details/116353774)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
1071 - Specified key was too long; max key length is 767 bytes
1071 - Specified key was too long; max key length is 767 bytes错误是指在创建索引时,索引字段的长度超过了数据库限制的最大长度767字节。这个错误可能会出现在不同的数据库系统中,比如MySQL。这个错误通常出现在创建唯一索引时,因为唯一索引需要保证索引字段的唯一性。如果你的索引字段过长,超过了数据库限制的最大长度,就会出现这个错误。解决这个问题的方法有几种。一种是缩短索引字段的长度,使其不超过最大长度限制。另一种是修改数据库的配置,增加最大索引长度的限制。还有一种是考虑使用前缀索引,将索引字段的前几个字符作为索引,以减少索引字段的长度。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [1071 - Specified key was too long; max key length is 767 bytes](https://blog.csdn.net/qq_38925911/article/details/118210392)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [MySQL错误“Specified key was too long; max key length is 1000 bytes”的解决办法](https://download.csdn.net/download/weixin_38606300/12835900)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [创建索引时,解决1071 Specified key was too long; max key length is 1000 bytes错误信息](https://blog.csdn.net/alpeace/article/details/116353774)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文