数据库返回“Row size too large. ”报错
问题描述
在DMS控制台中对RDS实例或自建MySQL数据库(ECS自建数据库或IDC自建数据库)执行SQL语句时,出现类似如下报错。
Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
问题原因
MySQL限制了单行的长度(65535字节),无论InnoDB存储引擎是否支持更大的存储,都会强制执行该限制,详情请参见MySQL官方文档。
解决方案
您可以根据实际情况,通过以下方法解决问题:
- 将表上一些varchar类型的大字段改为text或者blob类型的小字段。
- 登录DMS控制台,选择目标实例,选择目标库,然后右键单击目标表,选择编辑表结构。
- 单击列信息,根据实际情况,调整目标列的类型。
- 将表上一些varcahr类型的大字段根据业务实际需求缩小长度定义,节省行长。
- 登录DMS控制台,选择目标实例,选择目标库,然后右键单击目标表,选择编辑表结构。
- 单击列信息,根据实际情况,调整目标列的长度。
适用于
- 数据管理DMS
- 云数据RDS
说明:本文问题同样适用于自建MySQL数据库,即ECS自建数据库和IDC自建数据库。
https://help.aliyun.com/document_detail/188724.html
8.4.7 Limits on Table Column Count and Row Size
This section describes limits on the number of columns in tables and the size of individual rows.
Column Count Limits
MySQL has hard limit of 4096 columns per table, but the effective maximum may be less for a given table. The exact column limit depends on several factors:
-
The maximum row size for a table constrains the number (and possibly size) of columns because the total length of all columns cannot exceed this size. See Row Size Limits.
-
The storage requirements of individual columns constrain the number of columns that fit within a given maximum row size. Storage requirements for some data types depend on factors such as storage engine, storage format, and character set. See Section 11.7, “Data Type Storage Requirements”.
-
Storage engines may impose additional restrictions that limit table column count. For example,
InnoDB
has a limit of 1017 columns per table. See Section 14.23, “InnoDB Limits”. For information about other storage engines, see Chapter 15, Alternative Storage Engines. -
Each table has an
.frm
file that contains the table definition. The definition affects the content of this file in ways that may affect the number of columns permitted in the table. See Limits Imposed by .frm File Structure.
The maximum row size for a given table is determined by several factors:
-
The internal representation of a MySQL table has a maximum row size limit of 65,535 bytes, even if the storage engine is capable of supporting larger rows.
BLOB
andTEXT
columns only contribute 9 to 12 bytes toward the row size limit because their contents are stored separately from the rest of the row. -
The maximum row size for an
InnoDB
table, which applies to data stored locally within a database page, is slightly less than half a page for 4KB, 8KB, 16KB, and 32KBinnodb_page_size
settings. For example, the maximum row size is slightly less than 8KB for the default 16KBInnoDB
page size. For 64KB pages, the maximum row size is slightly less than 16KB. See Section 14.23, “InnoDB Limits”.If a row containing variable-length columns exceeds the
InnoDB
maximum row size,InnoDB
selects variable-length columns for external off-page storage until the row fits within theInnoDB
row size limit. The amount of data stored locally for variable-length columns that are stored off-page differs by row format. For more information, see Section 14.11, “InnoDB Row Formats”. -
Different storage formats use different amounts of page header and trailer data, which affects the amount of storage available for rows.
-
For information about
InnoDB
row formats, see Section 14.11, “InnoDB Row Formats”. -
For information about
MyISAM
storage formats, see Section 15.2.3, “MyISAM Table Storage Formats”.
-
Row Size Limit Examples
-
The MySQL maximum row size limit of 65,535 bytes is demonstrated in the following
InnoDB
andMyISAM
examples. The limit is enforced regardless of storage engine, even though the storage engine may be capable of supporting larger rows.mysql> CREATE TABLE t (a VARCHAR(10000), b VARCHAR(10000), c VARCHAR(10000), d VARCHAR(10000), e VARCHAR(10000), f VARCHAR(10000), g VARCHAR(6000)) ENGINE=InnoDB CHARACTER SET latin1; ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
mysql> CREATE TABLE t (a VARCHAR(10000), b VARCHAR(10000), c VARCHAR(10000), d VARCHAR(10000), e VARCHAR(10000), f VARCHAR(10000), g VARCHAR(6000)) ENGINE=MyISAM CHARACTER SET latin1; ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
In the following
MyISAM
example, changing a column toTEXT
avoids the 65,535-byte row size limit and permits the operation to succeed becauseBLOB
andTEXT
columns only contribute 9 to 12 bytes toward the row size.mysql> CREATE TABLE t (a VARCHAR(10000), b VARCHAR(10000), c VARCHAR(10000), d VARCHAR(10000), e VARCHAR(10000), f VARCHAR(10000), g TEXT(6000)) ENGINE=MyISAM CHARACTER SET latin1; Query OK, 0 rows affected (0.02 sec)
The operation succeeds for an
InnoDB
table because changing a column toTEXT
avoids the MySQL 65,535-byte row size limit, andInnoDB
off-page storage of variable-length columns avoids theInnoDB
row size limit.mysql> CREATE TABLE t (a VARCHAR(10000), b VARCHAR(10000), c VARCHAR(10000), d VARCHAR(10000), e VARCHAR(10000), f VARCHAR(10000), g TEXT(6000)) ENGINE=InnoDB CHARACTER SET latin1; Query OK, 0 rows affected (0.02 sec)
-
Storage for variable-length columns includes length bytes, which are counted toward the row size. For example, a
VARCHAR(255) CHARACTER SET utf8mb3
column takes two bytes to store the length of the value, so each value can take up to 767 bytes.The statement to create table
t1
succeeds because the columns require 32,765 + 2 bytes and 32,766 + 2 bytes, which falls within the maximum row size of 65,535 bytes:mysql> CREATE TABLE t1 (c1 VARCHAR(32765) NOT NULL, c2 VARCHAR(32766) NOT NULL) ENGINE = InnoDB CHARACTER SET latin1; Query OK, 0 rows affected (0.02 sec)
The statement to create table
t2
fails because, although the column length is within the maximum length of 65,535 bytes, two additional bytes are required to record the length, which causes the row size to exceed 65,535 bytes:mysql> CREATE TABLE t2 (c1 VARCHAR(65535) NOT NULL) ENGINE = InnoDB CHARACTER SET latin1; ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
Reducing the column length to 65,533 or less permits the statement to succeed.
mysql> CREATE TABLE t2 (c1 VARCHAR(65533) NOT NULL) ENGINE = InnoDB CHARACTER SET latin1; Query OK, 0 rows affected (0.01 sec)
-
For
MyISAM
tables,NULL
columns require additional space in the row to record whether their values areNULL
. EachNULL
column takes one bit extra, rounded up to the nearest byte.The statement to create table
t3
fails becauseMyISAM
requires space forNULL
columns in addition to the space required for variable-length column length bytes, causing the row size to exceed 65,535 bytes:mysql> CREATE TABLE t3 (c1 VARCHAR(32765) NULL, c2 VARCHAR(32766) NULL) ENGINE = MyISAM CHARACTER SET latin1; ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
For information about
InnoDB
NULL
column storage, see Section 14.11, “InnoDB Row Formats”. -
InnoDB
restricts row size (for data stored locally within the database page) to slightly less than half a database page for 4KB, 8KB, 16KB, and 32KBinnodb_page_size
settings, and to slightly less than 16KB for 64KB pages.The statement to create table
t4
fails because the defined columns exceed the row size limit for a 16KBInnoDB
page.mysql> CREATE TABLE t4 ( c1 CHAR(255),c2 CHAR(255),c3 CHAR(255), c4 CHAR(255),c5 CHAR(255),c6 CHAR(255), c7 CHAR(255),c8 CHAR(255),c9 CHAR(255), c10 CHAR(255),c11 CHAR(255),c12 CHAR(255), c13 CHAR(255),c14 CHAR(255),c15 CHAR(255), c16 CHAR(255),c17 CHAR(255),c18 CHAR(255), c19 CHAR(255),c20 CHAR(255),c21 CHAR(255), c22 CHAR(255),c23 CHAR(255),c24 CHAR(255), c25 CHAR(255),c26 CHAR(255),c27 CHAR(255), c28 CHAR(255),c29 CHAR(255),c30 CHAR(255), c31 CHAR(255),c32 CHAR(255),c33 CHAR(255) ) ENGINE=InnoDB ROW_FORMAT=COMPACT DEFAULT CHARSET latin1; ERROR 1118 (42000): 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.
https://dev.mysql.com/doc/refman/5.7/en/column-count-limit.html?spm=a2c4g.11186623.0.0.4fb62eebD26xs3
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
2017-07-29 Re:从零开始的领域驱动设计
2017-07-29 领域驱动设计和Spring
2017-07-29 深入JVM分析spring-boot应用hibernate-validator
2017-07-29 深入Spring Boot:那些注入不了的Spring占位符(${}表达式)
2016-07-29 cat监控平台环境搭建 专题
2016-07-29 MySQL的用户密码过期功能详解
2016-07-29 设计模式:观察者模式(有利于代码解耦)