mysql innodb 的 row size上限

背景

在项目使用中,出现了以下报错:

Error Code: 1118 - Row size too large (> 8126).
Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help.
In current row format, BLOB prefix of 768 bytes is stored inline.

上面报错,这就涉及到了row size的上限,也有可能会涉及到file format的设置。

一些上限

  • 创建表报错:maximum row size > 65535
  • 创建表报错:row size too large > 8126
  • 插入数据报错:row size too larget > 8126

这里主要讲第三种报错,插入数据的时候触发的报错。先要理清file format和row format两个概念。

个人理解修改这两个参数都有可能解决掉问题。为啥是有可能,因为file format只是部分长字段类型的设置。

File format

先解释下file forma。这是用于varchat或者text字段存储数据的方案。file format有两种,分别是Antelope和Barracuda。

Antelope模式

在MySQL 5.6之前的版本,默认file format是Antelope。

意思是,对于varchar和text字段,会将内容的前768字段放置在index record中,后面再接20个字节的指针。

剩下内容会放置在BLOB page中。

假设有11个text字段,每个字段都是1000字节。那么在插入数据的时候,row size = (768+20)* 11 = 8668 > 8126,将会触发row size too larget > 8126报错。

如果使用Antelope模式,不建议使用超过10个text或varchar字段。

Barracuda模式

Barracude会将所有数据放在BLOB page中,在index record里面只放20个字节的指针。

设置切换

查询File format设置:

show variables like "%innodb_file%";

my.cnf 设置

innodb_file_format = Barracuda #
innodb_file_per_table = 1
innodb_large_prefix = 1

Row format

innodb引擎的行格式(row format)有两种。分别是compact和dynamic/compressed。

ALTER TABLE test ROW_FORMAT=COMPRESSED;

SHOW TABLE STATUS IN test_db;

这里还是之说Antelope模式下使用text的问题。普通的数值类型,其实很难超8126的长度限制,就不说了。在Antelope模式下,text字段的前768会存储在index record中,会占用row size的768+2个字节。所以text/varchar字段不能太多。除非确定不会太长。



# 验证测试的sql create table text2
(
text1 longtext,
text2 longtext,
text3 longtext,
text4 longtext,
text5 longtext,
text6 longtext,
text7 longtext,
text8 longtext,
text9 longtext,
text10 longtext,
text11 longtext
) ENGINE=InnoDB DEFAULT CHARSET=ascii; insert into text2 values(
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000)
); insert into text2 values(
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',197) # repeat('y',198) error
); -------- create table text3
(
text1 longtext,
text2 longtext,
text3 longtext,
text4 longtext,
text5 longtext,
text6 longtext,
text7 longtext,
text8 longtext,
text9 longtext,
text10 longtext,
text11 longtext
) ENGINE=INNODB DEFAULT CHARSET=ascii ROW_FORMAT=COMPRESSED; insert into text3 values(
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000),
repeat('y',1000)
);

mysql row size上限的更多相关文章

  1. mysql 报Row size too large 65535 原因与解决方法

    报错信息:Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535 ...

  2. Mysql [Err] 1118 - Row size too large

    首先声明,对MySQL不懂,很多都不知道原因 设计了一个表,里面很多text字段,然后填进去的东西太多(用的是Python的MySQLdb),报错: _mysql_exceptions.Operati ...

  3. mysql触发器应用和创建表错误代码: 1118 Row size too large. 解决

    1.针对数据库查询问题的方便,可以建立重要表的log备份记录表,在主表的添加,修改,删除添加触发器,修改触发器增加触发字段的点,限制条件. 数据库log表查问题比从线上多台服务器上下载日志文件相对方便 ...

  4. Mysql_大字段问题Row size too large.....not counting BLOBs, is 8126.

    [问题描述] 1.从myslq(5.7.19-0ubuntu0.16.04.1)中导出sql脚本,导入到mysql(5.5.27)中,报如下错误:Row size too large. The max ...

  5. Limits on Table Column Count and Row Size Databases and Tables Table Size 最大行数

    MySQL :: MySQL 8.0 Reference Manual :: C.10.4 Limits on Table Column Count and Row Size https://dev. ...

  6. MySQLSyntaxErrorException: Row size too large 转摘自:https://confluence.atlassian.com/display/CONFKB/MySQLSyntaxErrorException%3A+Row+size+too+large

    Symptoms The following appears in the atlassian-confluence.log: Caused by: com.mysql.jdbc.exceptions ...

  7. 转:MySQL Row Format(MySQL行格式详解)

    MySQL Row Format(MySQL行格式详解) --转载自登博的博客

  8. 【bug】 1118 Row size too large

    1118 Row size too large Every table (regardless of storage engine) has a maximum row size of 65,535 ...

  9. index row size 2720 exceeds maximum 2712 for index "xxx" ,Values larger than 1/3 of a buffer page cannot be indexed.

    记录一个bug情况: 我有个表NewTable,复合主键(slaveid,resid,owner) CREATE TABLE "public"."NewTable&quo ...

随机推荐

  1. Django rest framework(3)----节流

    目录 Django组件库之(一) APIView源码 Django restframework (1) ----认证 Django rest framework(2)----权限 Django res ...

  2. ecshop数据库结构和字段介绍(转载)

    ecs_account_log:账户变动日志(注册用户充值.支付等记录信息)字段 类型 Null 默认 字段说明log_id mediumint(8) 否 无 日志IDuser_id mediumin ...

  3. Lake Counting-C++

    Description Due to recent rains, water has pooled in various places in Farmer John's field, which is ...

  4. Git远程版本库

    目前为止,所有的Git操作都是在一个本地版本库中.现在是时候来体验Git分布式的特性了. 说到远程版本库,大家最为熟悉的就是GitHub了,它实际上就相当于一个远程版本库,托管着所有的本地版本库的提交 ...

  5. JS+Jquery自定义格式导出HTML为Word(下列插件同样可以用于Excel导出)

    这里的word导出主要采用了jquery.wordexport.js.FileSaver.js,做功能之前我也是找了很多网上的资料,里面涉及到js导出word的用的都是这个插件,只是在自定义样式这一块 ...

  6. IT界的复仇者联盟解读

    漫威宇宙应用到IT界也是可以解读的,自从编程语言分了派系后,故事就多了,今天我们就用漫威宇宙的故事来解读一下IT界的故事. 漫威宇宙其实也就讲了一件事,整个宇宙就好比一个Java项目,其中有一群叫做美 ...

  7. 💡我们的表单解决方案 el-form-renderer

    前言 本文将介绍我们的表单解决方案 @femessage/el-form-renderer,展示我们在 Vue 技术栈下,我们是如何处理以下问题的: 表单项动态显示或隐藏 表单数据联动 表单输入/输出 ...

  8. Shiro权限管理框架(一):Shiro的基本使用

    首发地址:https://www.guitu18.com/post/2019/07/26/43.html 核心概念 Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码 ...

  9. Flutter学习笔记(12)--列表组件

    如需转载,请注明出处:Flutter学习笔记(12)--列表组件 在日常的产品项目需求中,经常会有列表展示类的需求,在Android中常用的做法是收集数据源,然后创建列表适配器Adapter,将数据源 ...

  10. 关于STM32F103+ESP8266+阿里云过程之修改SDK连接至阿里云(二)

    继上篇的阿里云物联云平台设置之后,接下来的工作就是对安信可官方给的sdk进行修改 安信可ESP系列集成环境,SDK,aliyun_mqtt_app,下载地址在上一篇博客,https://www.cnb ...