mysql size_mysql row size上限

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)

);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值