MySQL错误汇总

一、ERROR 1118 (42000): Row size too large

问题背景:修改表字段(数据类型为varchar)长度时提示1118

问题原因MySQL对数据表column的数量以及行记录大小进行了限制,所以在创建数据表或者通过alter修改表结构时可能会触发1118错误

解决方案:保证行记录允许最大字段和在允许范围内,其中对于BLOBTEXT分别占用9到12字节(bytes)

MySQL对于数据表允许最大行记录取决与以下几个因素:

  • MySQL服务器本身允许的最大行限制为65535字节,即使存储引擎可以支持更大的行;其中对于BLOBTEXT只占行记录的9到12字节,字段内容不计算在内

  • 对于InnoDB引擎而言,数据存储按照数据页的形式,允许的最大行记录略小于数据页的一半(数据页通过参数innodb_page_size设置,支持4KB、8KB、16KB、32KB,默认为16KB)。例如,对于默认的16KB InnoDB页面大小,最大行大小略小于8KB

    如果包含可变长度列的行超过了InnoDB的最大行大小,InnoDB会选择可变长度列用于外部页外存储,直到该行符合InnoDB的行大小限制。对于页外存储的可变长度列,本地存储的数据量因行格式而异。

    1
    2
    3
    4
    5
    6
    7
    8
    mysql> show variables like 'innodb_page_size';
    +------------------+-------+
    | Variable_name | Value |
    +------------------+-------+
    | innodb_page_size | 16384 |
    +------------------+-------+
    1 row in set (0.01 sec)

  • 不同的数据存储格式(storage format)会包含不同数量的页头和尾部数据,这些信息也会影响行的可用存储;

    关于InnoDB行格式的介绍可以参考:https://dev.mysql.com/doc/refman/8.0/en/innodb-row-format.html

示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- 建表时,超过允许最大行记录
create table max_row_size_test(
id int primary key,
name1 varchar(10000),
name2 varchar(10000)
);


mysql> create table max_row_size_test(
-> id int primary key,
-> name1 varchar(10000),
-> name2 varchar(10000)
-> );
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


-- 修改表结构时超过允许最大行记录
create table max_row_size_test(
id int primary key,
name1 varchar(10000),
name2 varchar(10)
);

mysql> create table max_row_size_test(
-> id int primary key,
-> name1 varchar(10000),
-> name2 varchar(10)
-> );
Query OK, 0 rows affected (0.02 sec)

mysql> alter table max_row_size_test modify column name2 varchar(10000);
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

参考来源:https://dev.mysql.com/doc/refman/8.0/en/innodb-row-format.html


MySQL错误汇总
https://probiecoder.cn/mysql/errors.html
作者
duwei
发布于
2024年5月8日
许可协议