Mysql报错:1118 - Row size too large. The maximum row size for the used table bype, not counting Bl0Bs,

报错信息

今天在使用mysql建表时报错:1118 - Row size too large. The maximum row size for the used table bype, not counting Bl0Bs, is 65535. This indudes storage overhead, check the manua. You have to change some columns to TEXT or BLOBs。
在这里插入图片描述
大概意思就是建表时的varchar字段太多或者太大了,导致超过了最大的 65535 限制,所以报错了。

模拟报错情况

CREATE TABLE tb_test (
    row1 VARCHAR ( 10000 ) DEFAULT NULL,
    row2 VARCHAR ( 10000 ) DEFAULT NULL,
    row3 VARCHAR ( 10000 ) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

> 1118 - 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

解决方法

方法一

将varchar字段的长度改小。

CREATE TABLE tb_test (
    row1 VARCHAR ( 5000 ) DEFAULT NULL,
    row2 VARCHAR ( 5000 ) DEFAULT NULL,
    row3 VARCHAR ( 5000 ) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

方法二

将过长的varchar类型字段改为text

CREATE TABLE tb_test(
    row1 VARCHAR ( 10000 ) DEFAULT NULL,
    row2 text DEFAULT NULL,
    row3 VARCHAR ( 10000 ) DEFAULT NULL
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4

方法三

如果是数据库表字段过多导致报错的情况,建议可以考虑垂直分表。


参考文章:
行大小不能超过 65535 问题

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值