Index column size too large. The maximum column size is 767 bytes.

本文介绍了解决MySQL数据库中因InnoDB引擎表索引字段长度超过767字节而产生的错误的方法。通过调整innodb_large_prefix参数、改变row_format为Dynamic或Compressed,并重新创建表或修改表结构,可以成功创建大字段或多字段组合的索引。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在MySQL数据库上建立索引时,出现错误Index column size too large. The maximum column size is 767 bytes.
由于 MySQL Innodb 引擎表索引字段长度的限制为 767 字节,因此对于多字节字符集的大字段(或者多字段组合索引),创建索引会出现上面的错误。

解决方案

Step 1 :设置参数 innodb_large_prefix 为 ON

set global innodb_file_format = BARRACUDA;
set global innodb_large_prefix = ON;

Step 2:创建表的时候指定表的 row format 格式为 Dynamic 或者 Compressed
create table tb_name
(
  ……
) 
ROW_FORMAT=DYNAMIC ENGINE=InnoDB  DEFAULT CHARSET=utf8;
Step 3:对于已经创建的表修改表的row_format
alter table <table_name> row_format=dynamic;
alter table <table_name> row_format=compressed;

经过上述步骤之后,再继续创建索引就可以成功了。

alter table <table_name> add unique index(column_name);
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值