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. Linux 文件编程、时间编程基本函数

    文件编程 文件描述符 fd --->>>数字(文件的身份证,代表文件身份),通过 fd 可找到正在操作或需要打开的文件. 基本函数操作: 1)打开/创建文件 int open (co ...

  2. Netty编码流程及WriteAndFlush()的实现

    编码器的执行时机 首先, 我们想通过服务端,往客户端发送数据, 通常我们会调用ctx.writeAndFlush(数据)的方式, 入参位置的数据可能是基本数据类型,也可能对象 其次,编码器同样属于ha ...

  3. python课堂整理1

      1.变量 变量只能由字母.数字.下划线组成 特例:1.变量不能用数字开头    2.不能是python的关键字 3.最好不要和python内置的东西重复 让变量名有意义 些 python3的关键字 ...

  4. 解决win10下MySQL 8.0登录Access denied for user 'root'@'localhost' (using password: YES)的问题

        近些时间在开始学MySQL,安装挺顺利的,按照网上现成的教程就能安装成功.     但是,在输入 mysql -uroot -p     再输入密码时,遇到了这个情况 Access denie ...

  5. jQuery框架操作CSS

    3.1 jQuery框架的CSS方法 jQuery框架提供了css方法,我们通过调用该方法传递对应的参数,可以方便的来批量设置标签的CSS样式. 使用JavaScript设置标签的样式相对来说比较麻烦 ...

  6. MicroPython TPYBoard v201 简易家庭气象站的实现过程

    转载请注明文章来源,更多教程可自助参考docs.tpyboard.com,QQ技术交流群:157816561,公众号:MicroPython玩家汇 前言 上一篇教程中我们实现了一个简单网页的显示.本篇 ...

  7. javaweb入门-----request与response的作用

    request对象和request对象的原理 1.request和response对象request对象和request对象的原理时由服务器创建的,我们来使用它们 2.request对象是来获取请求消 ...

  8. eclipse Mac 下补全代码

    1. 每次输入都自动提示 点击 Eclipse,使其成为第一响应者,preferences->Java->Editor->Content Assist再右下角 Auto activa ...

  9. Docker部署ELK 日志归集

    ELK ELK是Elasticsearch.Logstash.Kibana的缩写,使用ELK的原因是因为公司使用Spring cloud部署了多个微服务,不同的微服务有不同的日志文件,当生产上出现问题 ...

  10. codeforces 371 C-Hamburgers

    一个乱七八糟的故事背景,可以练练英语阅读. 大概的意思是Polycarpus喜欢汉堡,现在他有你ns片香肠片,nb面包,nc块起司,有r卢布,每种东西都有价格,如果不够他可以去商店买(商店里面各种东西 ...