mysql 联合索引 too long 错误

解密CANoe数据回放:从BLF到ASC的格式转换与优化策略 本文深入解析CANoe数据回放中BLF与ASC格式的转换与优化策略,帮助工程师高效处理汽车电子测试数据。详细介绍了两种格式的特性、转换方法及性能优化技巧,包括CANoe内置功能、命令行自动化和第三方工具应用,提升故障诊断和系统验证效率。 阅读详情

If you’ve ever tried to add an index that includes a long varchar column to an InnoDB table in MySQL, you may have seen this error:

 
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

The character limit depends on the character set you use. For example if you use latin1 then the largest column you can index is varchar(767) , but if you use utf8 then the limit isvarchar(255) . There is also a separate 3072 byte limit per index. The 767 byte limit is per column, so you can include multiple columns (each 767 bytes or smaller) up to 3072 total bytes per index, but no column longer than 767 bytes. (MyISAM is a little different. It has a 1000 byte index length limit, but no separate column length limit within that).

One workaround for these limits is to only index a prefix of the longer columns, but what if you want to index more than 767 bytes of a column in InnoDB?

In that case you should consider using innodb_large_prefix , which was introduced in MySQL 5.5.14 and allows you to include columns up to 3072 bytes long in InnoDB indexes. It does not affect the index limit, which is still 3072 bytes as quoted in the manual :

The InnoDB internal maximum key length is 3500 bytes, but MySQL itself restricts this to 3072 bytes. This limit applies to the length of the combined index key in a multi-column index.

Read on for details and examples about innodb_large_prefix .

Here are a few pre-requisites for using innodb_large_prefix :

The default file format is still Antelope for backwards compatibility, and the default row format is COMPACT.

You can set both innodb_file_format and innodb_large_prefix dynamically, but you should also set them in my.cnf so they survive a restart.

Here’s an example. If I try to create this table with innodb_large_prefix disabled I get an error:

 
mysql> create table if not exists utf8_test (
    ->   day date not null,
    ->   product_id int not null,
    ->   dimension1 varchar(500) character set utf8 collate utf8_bin not null,
    ->   dimension2 varchar(500) character set utf8 collate utf8_bin not null,
    ->   unique index unique_index (day, product_id, dimension1, dimension2)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

If I enable innodb_large_prefix I can create the table successfully:

 
mysql> set global innodb_file_format = BARRACUDA;
Query OK, 0 rows affected (0.00 sec)

mysql> set global innodb_large_prefix = ON;
Query OK, 0 rows affected (0.00 sec)

mysql> create table if not exists utf8_test (
    ->   day date not null,
    ->   product_id int not null,
    ->   dimension1 varchar(500) character set utf8 collate utf8_bin not null,
    ->   dimension2 varchar(500) character set utf8 collate utf8_bin not null,
    ->   unique index unique_index (day, product_id, dimension1, dimension2)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
Query OK, 0 rows affected (0.02 sec)

The examples are similar for latin1 , but I can use columns three times as long since it’s a single-byte character set.

 
mysql> create table if not exists latin1_test (
    ->   day date not null,
    ->   product_id int not null,
    ->   dimension1 varchar(1500) not null,
    ->   dimension2 varchar(1500) not null,
    ->   unique index unique_index (day, product_id, dimension1, dimension2)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

mysql> set global innodb_file_format = BARRACUDA;
Query OK, 0 rows affected (0.00 sec)

mysql> set global innodb_large_prefix = ON;
Query OK, 0 rows affected (0.00 sec)

mysql> create table if not exists latin1_test (
    ->   day date not null,
    ->   product_id int not null,
    ->   dimension1 varchar(1500) not null,
    ->   dimension2 varchar(1500) not null,
    ->   unique index unique_index (day, product_id, dimension1, dimension2)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
Query OK, 0 rows affected (0.02 sec)

And here’s what happens if I try to create an index longer than 3072 bytes:

 
mysql> create table if not exists long_index_test (
    ->   day date not null,
    ->   product_id int not null,
    ->   dimension1 varchar(1500) not null,
    ->   dimension2 varchar(1500) not null,
    ->   dimension3 varchar(1500) not null,
    ->   unique index unique_index (day, product_id, dimension1, dimension2, dimension3)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
ERROR 1071 (42000): Specified key was too long; max key length is 3072 bytes
matlab之作图设置游标的精度 matlab画出的figure游标的精度往往是固定的,这就对我们的调试和查看数据造成了不便。 那么怎么修改游标的精度呢? 首先,获取游标dcm_obj = datacursormode(gcf);然后对游标的精度进行设置:set(dcm_obj,'UpdateFcn',@NewCallback)这个NewCallback是什么东西呢?这是一个可以返回游标精度的函数,具体内容如下:function 阅读详情

相关推荐

手把手教你设计热电偶信号采集电路:从运放选型到ADC配置全流程

本文详细解析了热电偶信号采集电路的设计全流程,重点涵盖从高精度运放选型、差分放大电路设计到ADC配置与软件处理的工程实践。针对热电偶输出的微弱毫伏级差分信号,文章深入探讨了如何克服噪声、实现冷端补偿,并提供了具体的器件选型建议与电路调试技巧,旨在帮助工程师构建稳定可靠的高精度温度测量系统。

weixin_29169899的博客 435

mysql too long_mysql中data too long for column错误的一种解决办法

首先说明一下问题先:本人做了一个在线知识仓库之类的JSP小网站,页面编码为UTF-8,但在运行中老是出现乱码,经检查发现是mysql数据库出现了问题。Q1.不能插入中文的数据,一插入就会提示data too long for column ''的错误。上网找了一下,才明白mysql的默认编码格式是latin1,与utf-8的编码不同。按照网上的高手的说明,我先将原来的数据库删除重建1.create...

weixin_36397372的博客 3467

基于UWB技术的自动跟随避障系统设计研究

基于UWB技术的自动跟随避障系统设计研究 摘要:目前我国针对自动跟随避障系统方面的研究较少,同时国内自动跟随避障系统仍然处在未成熟阶段,多数仍停留在应用蓝牙控制或摄像头捕捉这类跟随方式,但这类方式在实际应用过程中往往会出现易受干扰,精度差,易受环境干扰等问题,这不仅会降低自动跟随避障系统的性能,同时也会对用户造成诸多困扰。因此,就需要结合目前较为有效的UWB技术,对自动跟随避障系统进行设计。基于此,本文首先将会针对UWB技术展开概述,而后对基于UWB技术的自动跟随避障系统组成展开分析,进而对基于UWB技术的

qq_43543515的博客 8000

mysql 索引 too long_mysql 联合索引 too long 错误

If you’ve ever tried to add an index that includes a long varchar column to an InnoDB table in MySQL, you may have seen this error:ERROR 1071 (42000): Specified key was too long; max key length is 767...

weixin_30421043的博客 665

后台扫描工具 - 御剑(珍藏版)附下载

版本说明:御剑后台扫描珍藏版 下载地址:安装包放下方网盘里了 链接:https://pan.baidu.com/s/1Bn7GtWb7AStcjzVahFOjSQ 提取码:zkaq 使用环境:windows 标题工具说明: 御剑后台扫描珍藏版是T00LS大牛的作品,方便查找用户后台登陆地址,同时也为程序开发人员增加了难度,尽量独特的后台目录结构。 附带很强大的字典,字典我们也是可以自己修改的,继续增加规则。 一、御剑后台扫描工具简介: 1、扫描线程自定义:用户可根据自身电脑的配置来设置调节扫描线程 2、

hackzkaq的博客 4万+

NVIDIA Isaac平台体验:Isaac Sim与Isaac ROS的快速了解

NVIDIA Isaac平台是一个专为机器人和人工智能(AI)打造的加速平台,旨在为开发者提供一个全面的工具集,以加速机器人相关应用的开发和部署。材质定义语言(MDL)是一种用于描述材质属性和行为的编程语言,能够精确地定义材质的光学特性和物理属性。NVIDIA Isaac Sim 通过支持 MDL,进一步提升了仿真环境中材质的真实感和细节表现。精确的材质定义:MDL 允许开发者精确地定义材质的光学特性和物理属性,如反射率、折射率、粗糙度和透明度等。这使得仿真环境中的物体看起来更加真实和自然。动态材质。

全世界的博客 4万+

mysql 无限递归出现 data too long for column 'xxx' 错误

1、先创建函数getChildId_bas_basic_tree 如下: CREATE FUNCTION `getChildId_bas_basic_tree`(rootId int) RETURNS varchar(21844) CHARSET gbk BEGIN DECLARE pTemp Varchar(21844); DECLARE ...

进击的Ace 771

【技术科普】破解政务跨系统数据壁垒!亘川一网统管平台多源数据同步技术解析

本文解析亘川一网统管平台多源数据同步技术,针对政务跨系统数据壁垒难题,介绍组件的数据采集、校验、审计留痕等核心能力,结合营商环境项目落地案例,对比传统开发模式差异,讲解开源组件的实践价值,为政务项目开发者提供落地参考。

weixin_67440240的博客 641

mysql导入错误:column too long(解决)

mysql导入时,错误,其中一个column too long, 但是我的数据是直接从服务器上导出,然后导入本地的, 应该是服务器的数据库版本跟本地不一样, 最后解决是导入时选择的编码改成UTF-8,如上图,默认是简体中文。 ...

825

YOLO11改进-注意力-引入Deformable Large Kernel Attention (DLKA) 解决多尺度、小目标、遮挡等问题

Deformable Large Kernel Attention (DLKA) 是一种用于视觉任务的注意力机制,旨在提升模型在处理不同尺寸和形状对象时的灵活性和性能。DLKA 的设计灵感源自传统的注意力机制,但通过引入可变形核(deformable kernel)来增强对局部特征的适应能力。

qq_64693987的博客 4046

【技能】OpenClaw Skill 操作钉钉(原理+20个实例)

OpenClaw Skill是遵循AgentSkills规范的自动化逻辑单元,用于指导AI助理调用钉钉工具。每个Skill包含SKILL.md文件,定义触发条件、执行逻辑和接口调用方式。Skill通过钉钉Connector插件实现API鉴权和请求转发,需配置ClientID/Secret等凭证。Skill加载路径包括工作目录、本地目录和内置目录,优先级由高到低。使用前需安装必备插件并配置钉钉权限,通过openclaw.json管理Skill开关和环境变量。ClawHub作为官方技能仓库支持Skill的安装和

海兰 1237

我的MySQL数仓文本字段报too long

20241205 我的MySQL数仓文本字段报too long。还真没存过这么大的文本,容易挨骂。这次赶工期,不得不临时解决搞一下。最近在研发过程中遇到中间表-数仓的数据问题,当时设计阶段设计的data_json字段类型 是text,实际debug过程发现报错 …too long…的报错。后来把整个数据字符串拿出来,统计了一下内容的长度length :75000 字符串。好家伙 这么大的么,text 的范围才65535字节,差不多2万多个字左右,肯定不够用。

ahauedu的专栏 1526

ollama使用CPU安装qwen-coder模型_并在eclipse中使用ai coder插件_配置本地qwen-coder模型_ollama常用操作记录---AI大模型应用探索0002

文章摘要:作者分享了在Windows 10上安装和使用Ollama模型的过程。尝试了不同规模的qwen-coder模型(7b、1.5b和0.5b),发现7b模型响应极慢(需35分钟),而1.5b模型表现较好(3秒响应)。最终选择1.5b版本用于代码开发辅助,支持多语言自动补全。同时提到在最新版Eclipse中的AIcoder配置问题。文章重点比较了不同模型规模在CPU环境下的实际使用体验和响应速度差异。

添柴程序猿的专栏 695

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

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

u011250186的博客 91

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

MySQL 建索引时遇到 Specified key was too long; max key length is 767 bytes

遇到的问题 Specified key was too long; max key length is 767 bytes 今日在导入数据库时遇到了 Specified key was too long; max key length is 767 bytes错误

xiaozhegaa的博客 3万+

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

[小技巧12]“Specified key was too long” 错误背后:MySQL 索引长度深度详解

MySQL 索引长度详解:原理、限制与优化实践

分享工作中解决的问题,希望能帮到你 740

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

MySQL5.6建索引时遇到 Specified key was too long; max key length is 767 bytes错误提示解决办法

一、错误提示 Specified key was too long; max key length is 767 bytes; 二、原因分析 在数据库中,索引的字段设置太长了,导致不支持。【根本原因:5.6版本的innodb大长度前缀默认是关闭的】。 mysql建立索引时,数据库计算key的长度是累加所有index用到的字段的char长度,在按照下面的比例乘起来 不能超过限定的key长度767: latin1 = 1 byte = 1 character uft8 = 3 byte = 1

提供C#相关开发 、云计算、运维测试、网络安全相关技术分享与服务,有意向可联系。 1万+

MySQL报错Specified key was too long

实践中遇到报错,修改一个字段的长度的时候报: Specified key was too long; max key length is 3072 bytes 是由于字段的长度变长了,导致包含在其上的联合所以超过长度 有一篇博文写的很清楚 错误讲解

weixin_42541360的博客 926

navicat为mysql建立索引

索引的目的是大大提高查询效率,还有读写效率。 kettle向sql里面插入,更新时,也要建立索引,可以大大提升处理时间。 但是建立索引报错:Specified key was too long; max key length is 1000 bytes 这是mysql中,索引字段的类型设置的总体过长,看一下fields里面字段类型,总体加起来不超过1000字节 注意,字段长度,是char长

longshenlmj的专栏 1万+

创建索引时,解决1071 Specified key was too long; max key length is 1000 bytes错误信息

在我们创建mysql的数据表索引时,一般为varchar字段相关索引(唯一,主键,联合索引,普通索引等),会报如下类似错误(mysql 版本:5.7.26): SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (S QL: alter table `users` add unique `users_username_uniqu..

Robb 1万+

建索引时或执行sql文件报 Specified key was too long; max key length is 767 bytes 错误的处理

原因 由于 MySQLInnodb 引擎表索引字段长度的限制为 767 字节,因此对于多字节字符集的大字段(或者多字段组合索引),创建索引会出现上面的错误。 以 utf8mb4 字符集 字符串类型字段为例:utf8mb4 是 4 字节字符集,则默认支持的索引字段最大长度是: 767 字节 / 4 字节每字符 = 191 字符,因此在 varchar(255) 或 char(255) 类型字段上创建索引会失败。 解决步骤 1.查看innodb_large_prefix,innodb_file_for.

qq_36173200的博客 742

mysql设置索引长度_修改Mysql索引长度限制

mysql 索引过长1071-max key length is 767 byte问题create table: Specified key was too long; max key length is 767 bytes原因数据库表采用utf8编码,其中varchar(255)的column进行了唯一键索引而mysql默认情况下单个列的索引不能超过767位(不同版本可能存在差异)于是utf8字...

weixin_34553878的博客 3228

mysql 索引长度限制_修改Mysql索引长度限制

mysql 索引过长1071-max key length is 767 byte问题create table: Specified key was too long; max key length is 767 bytes原因数据库表采用utf8编码,其中varchar(255)的column进行了唯一键索引而mysql默认情况下单个列的索引不能超过767位(不同版本可能存在差异)于是utf8字...

weixin_42115003的博客 3745

MySQL 建索引时 Specified key 'idx_t' was too long; max key length is 767 bytes 错误处理

在做 sql 优化时,对之前的表添加个索引,却给出了 Specified key 'idx_t' was too long; max key length is 767 bytes 提示,后来通过查询资料,发现 由于 MySQL Innodb 引擎表索引字段长度的限制为 767 字节,因此对于多字节字符集的大字段(或者多字段组合索引),创建索引会出现上面的错误。 以 utf8mb4 字符集 字...

molaifeng的专栏 5734

MySQL:Specified key was too long; max key length is 767 bytes.

建表语句: CREATE TABLE IF Not EXISTS api ( api varchar(500) not null , method varchar(50) not null default 'POST', PRIMARY key (api,method) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ...

weixin_30299539的博客 213

Zabbix5.0-插入数据库文件时报错:Specified key was too long; max key length is 767 bytes

Zabbix5.0-插入数据库文件时报错:Specified key was too long; max key length is 767 bytes 背景:之前成功安装过zabbix3.0、zabbix4.0转战5.0时出错: 执行:zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix 报错:Specified key was too long; max key length is 767 by

和忘了饭香一起学习 800
上一篇: 多列索引结构和原理
下一篇: 如何优化高流量站点的nginx和php-fpm的几个方面
dahuzix
博客等级 码龄15年 81粉丝 133原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值