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

2023-05-18,,

【问题描述】

1.从myslq(5.7.19-0ubuntu0.16.04.1)中导出sql脚本,导入到mysql(5.5.27)中,报如下错误:Row size too large. The maximum row size for the used table type, not counting BLOBs, is 8126. You have to change some columns to TEXT or BLOBs
2.程序向mysql(5.5.27)中存入数据报错如下:Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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.

【导致问题的原因】

原因是因为mysql-innodb是按照page存储数据的,每个page max size是16K,然后每个page两行数据,所以每行最大8K数据。如果你的字段是blob之类的话,会存储在page之外的溢出区里。
但是innodb默认的approach(羚羊)存储格式会把每个blob字段的前864个字节存储在page里,所以你的blob超过一定数量的话,单行大小就会超过8k,所以就报错了。

【解决思路】

解决方式是使用innodb的Barracuda(梭鱼)存储格式。这种格式对blob字段的处理方式是在page里面只存储一个20byte大小的指针,其他完全存在溢出区,所以轻易不会超过8K.

【详细步骤】

1.打开mysql的配置my.ini.在innodb配置中添加:innodb_file_per_table=1,(大概意思就是打开mysql每张表都是独立存储空间的开关)如下图:

 
2.然后命令检查上述开关是否打开:
SHOW VARIABLES LIKE '%per_table%'

如图就是打开的了。如果value值显示OFF,只需重启mysql服务即可。
3.设置mysql全局变量:innodb_file_format = Barracuda(梭鱼)
命令:set GLOBAL innodb_file_format = 'Barracuda';
然后检查下是否设置好了:
命令:show GLOBAL VARIABLES LIKE '%file_format%';

4.设置对应表的属性:ROW_FORMAT=DYNAMIC
ALTER TABLE zgzw_jibing_table ROW_FORMAT=DYNAMIC

按照如上步骤操作就OK了。

【声明】

本文参考了:http://blog.sina.com.cn/s/blog_8e9cceee0101k65j.html

Mysql_大字段问题Row size too large.....not counting BLOBs, is 8126.的相关教程结束。

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

下载本文的Word格式文档,以方便收藏与打印。