美文网首页
MySQL索引长度限制为767

MySQL索引长度限制为767

作者: 李得志_春风得意马蹄疾 | 来源:发表于2019-10-28 17:08 被阅读0次

1、当innodb_large_prefix为off,单列索引的长度限制为767。

show variables like 'innodb_large_prefix';
| innodb_large_prefix | OFF   |

字符集为utf8,单列varchar(255)是可以创建索引的上限,256即报错。

create table t2(name varchar(255));
alter table t2 add index n1(name);

create table t3(name varchar(256));
alter table t3 add index n1(name);
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

2、修改innodb_large_prefix为on。

set global innodb_large_prefix=1;
show variables like 'innodb_large_prefix';
| innodb_large_prefix | ON    |

3、varchar(256)是否能够建索引与表的row_format有关。

当表的row_format为Compact,单列索引的上限仍然是767。

alter table t3 add index n1(name);
ERROR 1709 (HY000): Index column size too large. The maximum column size is 767 bytes.

当表的row_format为Compressed,单列索引的上限是3072。

alter table t3 row_format=compressed key_block_size=8;
alter table t3 add index n1(name);

4、一张表的FILE_FORMAT和ROW_FORMAT

更改一张表的row_format同时也更改了这张表的file_format。Compact必定是Antelope(羚羊),dynamic和Compressed必定是Barracuda(梭鱼)。

select * from information_schema.innodb_sys_tables where name like '%t1%';

相关文章

  • MySQL索引长度限制为767

    1、当innodb_large_prefix为off,单列索引的长度限制为767。 字符集为utf8,单列varc...

  • MySQL提示 “Specified key was too l

    问题原因由于MySQL的InnoDB引擎表索引字段长度的限制为767字节,因此对于多字节字符集的大字段或者多字段组...

  • Specified key '%s' was t

    出现这个错误是在创建索引的时候,原因所选字段的长度超出了可以创建索引的最大长度,InnoDB是767字节,但是有时...

  • MySQL索引长度限制

    问题引入 想必不少开发者在工作过程中会听到同事或者在网上看到以下内容: MySQL索引长度不能超过191,需限制为...

  • MySQL中采用类型varchar(20)和varchar(25

    MySQL建立索引时如果没有限制索引的大小,索引长度会默认采用的该字段的长度,也就是说varchar(20)和va...

  • varchar(20)和varchar(255)的空间开销区别

    MySQL建立索引时如果没有限制索引的大小,索引长度会默认采用的该字段的长度,也就是说varchar(20)和va...

  • Mysql索引长度问题

    今天在做测试的时候,遇到一个问题,百撕不得其姐。先描述下场景,本想测试索引使用情况:explain select ...

  • 93 mysql 优化

    1 mysql默认情况下单个列的索引不能超过767位 可以启用innodb_large_prefix选项,将约束项...

  • Mysql char varchar text

    1.varchar类型的变化 MySQL 数据库的varchar类型在4.1以下的版本中的最大长度限制为255,其...

  • mysql InnoDB 索引长度问题

    mysql常用字符集 utf8 一个字符3bytes utf8mb4 一个字符4bytes 单列索引长度不能超过7...

网友评论

      本文标题:MySQL索引长度限制为767

      本文链接:https://www.haomeiwen.com/subject/nfibvctx.html