Specified key was too long; max key length is 1000 bytes

栏目: 数据库 · Mysql · 发布时间: 5年前

内容简介:使用mariadb创建数据表,遇到了这个是提示(Specified key was too long; max key length is 1000 bytes)。如果直接执行出现的错误是索引的长度限制是1000, 因为

使用mariadb创建数据表,遇到了这个是提示(Specified key was too long; max key length is 1000 bytes)。 原因是索引键太长了,超过了1000 ,出现这样的情况,调整一下索引的字段的长度就可以。下面说下遇到的具体情况。

创建一个数据表

create table if not exists `options`(
    `option_id` bigint(20) unsigned not null auto_increment,
    `option_name` varchar(251) not null default '',
    `option_value` longtext not null,
    `autoload` varchar(20) not null default 'no',
    primary key (`option_id`),
    unique key (`option_name`)
) engine=myisam  default charset=utf8mb4;

如果直接执行出现的错误是 (Specified key was too long; max key length is 1000 bytes)

出现的原因

  1. 索引过长超过的 1000
  2. 数据表引擎myisam的限制

修改的方式有两种,任何一种都可以修改

  1. 删除索引 unique key ( option_name )
  2. 修改索引的长度

说明1

索引的长度限制是1000, 因为 utf8mb4 一个字符是占用4个字节,所以修改的数要小 (1000/4 =250)

说明2

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

如果遇到了可能用的是 innodb 的引擎


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Refactoring

Refactoring

Martin Fowler、Kent Beck、John Brant、William Opdyke、Don Roberts / Addison-Wesley Professional / 1999-7-8 / USD 64.99

Refactoring is about improving the design of existing code. It is the process of changing a software system in such a way that it does not alter the external behavior of the code, yet improves its int......一起来看看 《Refactoring》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具