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. java高并发系列 - 第6天:线程的基本操作

    新建线程 新建线程很简单.只需要使用new关键字创建一个线程对象,然后调用它的start()启动线程即可. Thread thread1 = new Thread1(); t1.start(); 那么 ...

  2. Discuz ML! V3.X 代码注入漏洞

    Discuz ML! V3.X 代码注入漏洞 前言 Discuz!ML是一个由CodersClub.org创建的多语言,集成,功能齐全的开源网络平台,用于构建像"社交网络"这样的互 ...

  3. Java 技术交流群,微信群

    专注Java相关技术:SSM.Spring全家桶.微服务.MySQL.集群.dubbo.分布式.中间件.Linux.网络.多线程.Jenkins.Nexus.Docker.ELK等等! 由于微信群限制 ...

  4. Golang 受欢迎的原因:大道至简

    前言 Golang自2009年发布第一个版本,2012年发布1.0版本.在这10年的时间里,不断有开发者加入Golang的阵营中,不断共建Golang生态.其中比较有代表性的Golang编写软件作品是 ...

  5. 网络编程模型及TCP、UDP编程设计

    1.Linux网络模型 Linux网络编程--->>>socket套接字的编程 2.TCP网络模型                                          ...

  6. R030---手把手教程:你有一条RPA发送的工资条待查收

    ​一.缘起 前2天写了<R029---简述:用UiPath实现RPA(工作流程自动化)(基础知识篇)>,本篇作为补充. 实战出真知,以做代学,下面以一个HR的真实场景举例实践,用UiPat ...

  7. 《 C#语言学习笔记》——自动属性

    属性是访问对象状态的首选方式,因为它们禁止外部代码实现对象内部的数据存储机制.属性还对内部数据的访问方式有了更多控制.一般以非常标准的方式定义属性,即通过一个公共属性直接访问一个私有成员. 利用自动属 ...

  8. 將Python打包成 exe可执行文件

    利用Python寫了一個小腳本想要傳給使用Windows但沒有裝Python的朋友執行,這時候就可以利用將檔案包裝成exe檔案,讓沒有Python的朋友也可以執行.本篇將介紹利用套件「PyInstal ...

  9. 学习LayUI时自研的表单参数校验框架

    开发背景&痛点:每次写前端的表单的时候需要对表单里用户填写的内容进行校验,减少服务器压力,提前对已知错误对用户提示.每次会要写很多的if else等等对输入框中的内容进行判断,并对为空.格式不 ...

  10. Spring AOP 面向切面的Spring

    定义AOP术语 描述切面的常用术语有: 通知 (advice) 切点 (pointcut) 连接点 (joinpoint) 下图展示了这些概念是如何关联的 Spring 对AOP的支持 Spring提 ...