首页 > 其他分享 >Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535.

Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535.

时间:2023-05-17 10:44:07浏览次数:35  
标签:used varchar 字节 占用 长度 65535 NULL size

问题描述

新建表或者修改表varchar字段长度的时候,出现这个错误

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

在这里插入图片描述
大概意思就是行大小太大,不能超过65535
长度改为21842就正常了,这是为什么?


分析

最终我们执行正确的SQL语句

CREATE TABLE `all_type_forlan` (
  `id` int(20) NOT NULL COMMENT 'id',
  `base_info` varchar(21842) DEFAULT NULL COMMENT '基本详细',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

这里的21842长度是怎么来的?
首先它是什么意思?表示21842字符

首先来了解几个规则,对我们的字符数有影响的规则

1、MySQL规则

编码规则

不同字符集下,占用空间不一样
gbk编码中,1个字符占用2个字节
utf8编码(默认)中,1个字符占用3个字节
utf8mb4编码中,1个字符占用4个字节

存储规则

varchar除了存储字符,还需要额外的空间来存储长度和是否为NULL,分别占用1-2字节和1字节

行大小限制

MySQL 表的内部表示具有 65,535 字节的最大行大小限制,即使存储引擎能够支持更大的行。 BLOB 和 TEXT列仅对行大小限制贡献 9 到 12 个字节,因为它们的内容与行的其余部分分开存储

2、验证

根据行最大65535字节,我们选择utf8编码,那我们最多可以设置的字符数为65535/3=21845
在这里插入图片描述
还是报错了,因为我们还需要减去额外的存储(长度和是否为NULL),65535-3=65532/2=21844,设置成21844就成功了

验证NULL占用1个字节

65535-1-3=65531/3=21,843.66666666667,向下取整,最多只能21843,所以报错啦,看下图
说明:tinyint占用1个字节、varchar的长度和是否为NULL占用3个字节
在这里插入图片描述
我们把varchar字段设为不是null,此时21844可以设置成功
说明:65535-1-2=65532/3=21844

3、结论

所以,至此,我们就知道为什么21842才可以了
计算规则=(65535-4-2-1)/3=21,842.66666666667,向下取整,就是21842
说明:int占用4个字节,varchar的长度和是否为NULL占用3个字节,使用了utf8编码,1个字符占用3个字节


解决方案

如果长度需要加长,将字段类型改为TEXT或BLOB
如果只是想设置一个最大值,那可以根据计算规则进行调整


拓展

为什么我们经常使用varchar(255),不使用varchar(256)?

首先我们使用的varchar,除了存储字符内容,还需要额外存储长度和是否为NULL

因为varchar类型的字段长度在超过255后,需要2个字节来存储长度,因为1个字节=8位,可以表示的长度为255,2个字节=16位,可以表示的长度为65535
所以varchar(256)会比varchar(255)多占用1个字节来存储长度

MySQL列数限制

MySQL 对每个表有 4096 列的硬性限制,但对于给定的表,有效最大值可能会更少,因为表的最大行大小限制了列的数量

int类型的占用空间的大小范围

在这里插入图片描述

标签:used,varchar,字节,占用,长度,65535,NULL,size
From: https://www.cnblogs.com/huozhonghun/p/17407829.html

相关文章

  • [LeetCode] 1343. Number of Sub-arrays of Size K and Average Greater than or Equa
    Givenanarrayofintegers arr andtwointegers k and threshold,return *thenumberofsub-arraysofsize k andaveragegreaterthanorequalto *threshold.Example1:Input:arr=[2,2,2,2,5,5,5,8],k=3,threshold=4Output:3Explanation:Sub-a......
  • Commonly Used Prompts for Reducing Duplicate Rate
    Simplerewrite:Tryhardtorewritethefollowingcontent,makesurethemeaningisthesameastheoriginalmeaningbutjusttrytousedifferentwordsespeciallyformalwords:Rewriteabstractorsomecopiedtextsfromapaper:Rewritethefollowing......
  • [springboot] 上传文件时,报"org.apache.tomcat.util.http.fileupload.impl.FileSizeLi
    1问题描述基于springmvc/springboot的MultipartFile接口实现上传文件功能时,报如下错误日志[2023/05/1322:31:54.732][TID:N/A][INFO][http-nio-8769-exec-5][AccessPathWebFilter.java:85doFilter][3-4]request-path:http://love.pfr.kim/user-service/v1/file-re......
  • Element-plus中使用pagination显示sizes为中文
    需求描述使用分页组件中添加sizes信息,也就是一个下拉框,用户可以选择当前页的数据量<el-paginationbackgroundv-model:current-page="currentPage"v-model:page-size="pageSize":total="total":page-sizes="[5,10,15,20,25]"@current-change="......
  • ES维护篇-解决reason=Result window is too large, from + size must be less than or
    首先搞清楚这个报错是什么意思{"msg":"Elasticsearchexception[type=search_phase_execution_exception,reason=allshardsfailed];nestedexceptionisElasticsearchStatusException[Elasticsearchexception[type=search_phase_execution_exception,reason=alls......
  • nginx 10061: No connection could be made because the target machine actively ref
    nginx10061:Noconnectioncouldbemadebecausethetargetmachineactivelyrefusedit nginx重载配置一直有些不生效,查看后,发现nginx有4个,全部关闭掉,再重开nginx,正常了nginx.exe-squit,可以把正常的nginx退出掉,其他的nginx,任务管理器强制关闭掉startnginx开启nginx,o......
  • Electron设置窗口大小setSize遇到的问题
    应用场景登录页跳转主页-窗口放大主页跳转登录页-窗口缩小方法setSize()遇到的问题在主页退出登录时,窗口缩小时setSize()不生效查看官方文档发现设置了窗口最小范围时,会影响setSize()所以,setSzie()调用要放在setMinimumSize()、setMaximumSize()后面functioninitMain......
  • 关于error The "ApexChart" component has been registered but not used 问题的解决
    问题描述学习了vue之后,但是还没熟练使用的我,发现删除某些模块会使得整个界面报错,真的是又被无语到(被自己哈!)问题解决仔细看了看这个报错,发现是因为这个界面定义了一些vue模块,但是由于我的修改,导致它们被定义之后,并没有得到相应的调用;然后解决的话,就很简单,将我们对这些模块再这......
  • textarea autosize textarea 设置高度问题
    elementui里的 textarea 高度在没有设置autosize的时候可以用属性rows='x'来设置如果设置了autosize后,rows属性就失效了,本来想着用autosize="{minRows:1,maxRows:4}",来设置高度应该是可以的,但是textarea 默认  rows='2',所以方法行不通然后想着用textarea的高度......
  • global_size local_size clEnqueueNDRangeKernel OpenCL
    clEnqueueNDRangeKernel填入的形参:global_sizelocal_size global_size控制最终的workgroup数量,而且会平均分配到几个core上,比如global_size=8 然后有2个core,那么每个core分到4个wglocal_size控制每个core分到几个workitem,每个.cl文件里,已经hardcoding了一个workitem计......