mysql 创建表遇到单列的长度限制 ERROR 1074 (42000) 与 行长限制 ERROR 1118 (42000)_result: 1074 - column length too big for column ''-程序员宅基地

技术标签: # mysql opti table index  Row size too large  mysql  Column length too big  

os: centos 7.4
db: mysql 8.0.18

ERROR 1074 (42000): Column length too big for column ‘c0’ (max = 16383); use BLOB or TEXT instead
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

版本

# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core) 

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.18    |
+-----------+
1 row in set (0.00 sec)

mysql> show global variables like '%innodb_page_size%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| innodb_page_size | 16384 |
+------------------+-------+
1 row in set (0.00 sec)

mysql> show global variables like '%character%';
+--------------------------+----------------------------------------------------------------+
| Variable_name            | Value                                                          |
+--------------------------+----------------------------------------------------------------+
| character_set_client     | utf8mb4                                                        |
| character_set_connection | utf8mb4                                                        |
| character_set_database   | utf8mb4                                                        |
| character_set_filesystem | binary                                                         |
| character_set_results    | utf8mb4                                                        |
| character_set_server     | utf8mb4                                                        |
| character_set_system     | utf8                                                           |
| character_sets_dir       | /usr/local/mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/ |
+--------------------------+----------------------------------------------------------------+
8 rows in set (0.00 sec)

mysql建表的时候列长度有65535的限制,该数据库采用的字符集为 utf8mb4 ,最多用 4个字节存储,那么总的字符长度为 65535/4=16383.75。

错误

mysql> create table tmp_t0(c0 varchar(30000),c1 varchar(30000));
ERROR 1074 (42000): Column length too big for column 'c0' (max = 16383); use BLOB or TEXT instead
mysql> 
mysql> 
mysql> create table tmp_t0(c0 varchar(16383),c1 varchar(16384));
ERROR 1074 (42000): Column length too big for column 'c1' (max = 16383); use BLOB or TEXT instead
mysql> 
mysql> 
mysql> create table tmp_t0(c0 varchar(16383),c1 varchar(16383));
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

开始做一些尝试,单列 varchar(16383) 可以创建

 
mysql> create table tmp_t0(c0 varchar(16384));
ERROR 1074 (42000): Column length too big for column 'c0' (max = 16383); use BLOB or TEXT instead
mysql>
mysql>
mysql> create table tmp_t0(c0 varchar(16383));
Query OK, 0 rows affected (0.15 sec)
mysql>
mysql>
mysql> drop table tmp_t0;
Query OK, 0 rows affected (0.08 sec)

两列 varchar(16381), varchar(1) 可以创建

mysql> create table tmp_t0(c0 varchar(16383),c1 varchar(1));
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> 
mysql> 
mysql> create table tmp_t0(c0 varchar(16382),c1 varchar(1));
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> 
mysql>
mysql> create table tmp_t0(c0 varchar(16381),c1 varchar(1));
Query OK, 0 rows affected (0.18 sec)
mysql> 
mysql> drop table tmp_t0;
Query OK, 0 rows affected (0.08 sec)

三列 varchar(16380), varchar(1), varchar(1) 可以创建

mysql> create table tmp_t0(c0 varchar(16381),c1 varchar(1),c2 varchar(1));
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> 
mysql> 
mysql> create table tmp_t0(c0 varchar(16380),c1 varchar(1),c2 varchar(1));
Query OK, 0 rows affected (0.15 sec)

mysql> 
mysql> 
mysql> drop table tmp_t0;
Query OK, 0 rows affected (0.03 sec)

四列 varchar(16379), varchar(1), varchar(1), varchar(1) 可以创建

mysql> create table tmp_t0(c0 varchar(16380),c1 varchar(1),c2 varchar(1),c3 varchar(1));
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> 
mysql> 
mysql> create table tmp_t0(c0 varchar(16379),c1 varchar(1),c2 varchar(1),c3 varchar(1));
Query OK, 0 rows affected (0.22 sec)

mysql> drop table tmp_t0;
Query OK, 0 rows affected (0.02 sec)

包含一个 int4

mysql> create table tmp_t0(c0 varchar(16379),c1 varchar(1),c2 varchar(1),c3 varchar(1),c4 int4);
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> 
mysql> 
mysql> create table tmp_t0(c0 varchar(16378),c1 varchar(1),c2 varchar(1),c3 varchar(1),c4 int4);
Query OK, 0 rows affected (0.04 sec)

mysql> 
mysql> drop table tmp_t0;
Query OK, 0 rows affected (0.14 sec)

mysql> 

包含一个 int8

mysql> create table tmp_t0(c0 varchar(16379),c1 varchar(1),c2 varchar(1),c3 varchar(1),c4 int8);
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> 
mysql> 
mysql> create table tmp_t0(c0 varchar(16378),c1 varchar(1),c2 varchar(1),c3 varchar(1),c4 int8);
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> 
mysql> 
mysql> create table tmp_t0(c0 varchar(16377),c1 varchar(1),c2 varchar(1),c3 varchar(1),c4 int8);
Query OK, 0 rows affected (0.04 sec)

mysql> 
mysql> 
mysql> drop table tmp_t0;
Query OK, 0 rows affected (0.17 sec)

mysql> 

列计数限制

MySQL对于每个表具有4096个列的硬限制,但给定表的有效最大值可能较少。精确的列限制取决于几个因素:

1、表的最大行大小限制列的数量(可能是大小),因为所有列的总长度不能超过此大小。
请参阅 行大小限制

2、单个列的存储要求限制了适合给定最大行大小的列数。某些数据类型的存储要求取决于存储引擎,存储格式和字符集等因素。
请参见 数据类型存储要求

3、存储引擎可能会施加限制表列计数的额外限制。例如, InnoDB每个表的限制为1017列。请参见对InnoDB表的限制有关其他存储引擎的信息,
请参见替代存储引擎

4、每个表都有一个.frm包含表定义的文件。该定义以可能影响表中允许的列数的方式影响此文件的内容。
请参见.frm文件结构引起的限制

行大小限制

给定表格的最大行大小由以下几个因素决定:

1、MySQL表的内部表示形式的最大行大小限制为65,535字节,即使存储引擎能够支持较大的行。 BLOB并且 TEXT列只向行大小限制贡献9到12个字节,因为它们的内容与行的其余部分分开存储。

2、InnoDB 适用于数据库页面本地存储的数据 的表的最大行大小略小于4KB,8KB,16KB和32KB innodb_page_size 设置的一半页面 。例如,对于默认的16KB InnoDB页面大小,最大行大小略小于8KB 。对于64KB页面,最大行大小略小于16KB。
请参见 对InnoDB表的限制

3、如果包含可变长度列的InnoDB 行超过最大行大小,请InnoDB为外部页外存储选择可变长度列,直到该行适合InnoDB 行大小限制。存储在页外的可变长度列的本地存储的数据量按行格式而不同。有关更多信息,
请参见 InnoDB行存储和行格式

4、不同的存储格式使用不同数量的页眉和预告片数据,这会影响可用于行的存储量。

参考:

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/ctypyb2002/article/details/103409917

智能推荐

vs2010和Matlab R2012a 混合编程_matlabr2012a怎么运行代码-程序员宅基地

文章浏览阅读1.7k次。转自:http://blog.sina.com.cn/s/blog_4fc6546101011cu5.html本人系统Windows 7旗舰版,32位,采用由m文件构造动态链接库然后在visual studio中调用的方法。1. MATLAB 环境配置: 注:Matlab r2010b及以后版本才支持vs2010, 之前版本中mbuild命令输入后可能会_matlabr2012a怎么运行代码

分治法之合并排序(2021/1/23)_分治法合并程序-程序员宅基地

文章浏览阅读247次。问题引入代码实现#include<iostream>#include<cstdlib>using namespace std;struct Data{ int flag;};void MergeFunction(struct Data*list,int low,int middle,int high){ //申请辅助空间 int size=high-low; struct Data*space=(struct Data*)malloc(sizeof(struc_分治法合并程序

正规文法构造状态转换图,状态转换图构造正规文法---编译原理_文法状态图-程序员宅基地

文章浏览阅读7.9k次,点赞19次,收藏104次。从左线性正规文法出发,构造状态图注意:增设初态S,单圆圈表示例子从右线性正规文法出发,构造状态图注意:增设终态Z,双圆圈表示例子状态转换图构造左线性正规文法注意:写左线性正规文法时从终态开始例子状态转换图构造右线性正规文法注意:写右线性正规文法时从初态开始例子..._文法状态图

Codeforces 1445 B题_b. shooting time limit per test1 second memory lim-程序员宅基地

文章浏览阅读315次。codeforces 1455 B2021-01-14 打卡题,随便在codeforces上找了一道B. Jumpstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output题目描述:You are standing on the OX-axis at point 0 and you want to move to an integer point _b. shooting time limit per test1 second memory limit per test25

Java中public、protected、private和default的区别_变量、类和接口可以具有不同级别的可见性。描述private和default的级别有什么区别-程序员宅基地

文章浏览阅读3.8k次。public、protected、private和default都是java中的访问控制符其访问权限如下:public: 具有最大的访问权限,可以访问任何一个在classpath下的类、接口、异常等等。它往往用于对外提供调用的形式。protected:主要用来老保护子类,它所修饰的属性,方法,可由子类继承default:它是针对本包访问而设计的,任何处于本包下的类,接口,异常等,都可以相互访问。p..._变量、类和接口可以具有不同级别的可见性。描述private和default的级别有什么区别

Django实战搭建mock系统(五)_验证码功能_django mockserver-程序员宅基地

文章浏览阅读305次。一.注册,并实现验证码功能先准备好注册的模板静态页面:https://download.csdn.net/download/qq_38175040/19548394将模板页面放到template文件夹下面,然后在view里定义视图,去url里指定路径,都是老生常谈的东西了去url里面写路径最后注意一下register.html里的跳转语句访问页面成功接下来实现验证码功能我们使用Django captcha,这是别人已经造好的轮子,可以到GitHub看看项目的使用文档等详情。在命令行里_django mockserver

随便推点

MAC Addresses_addresses ct文件-程序员宅基地

文章浏览阅读697次。10046. MAC Addresses 收藏OUI:Organizationally Unique Identifiers 组织唯一标志符IAB:Individual Address Block 单独地址块ETH:ETHERTYPE 以太网类型 eth-eg: 0x809B AppleTalk协议 0x8137 IPX 0x86DD IPv6 0x0800 _addresses ct文件

Redis集群环境搭建以及Java连接Redis集群_java连接 redis集群代理模式-程序员宅基地

文章浏览阅读2.6k次。!!!服务器版本为Centos7.3 阿里云本文档仅为单个服务器下,创建六个不同端口号的reids服务模拟集群环境。一. 安装Redis5.01. 下载redis5.0进入到usr/local目录,执行下载命令下载redis压缩包cd usr/localwget http://download.redis.io/releases/redis-5.0.0.tar.gz2.解压后安..._java连接 redis集群代理模式

网易企业邮箱在outlook2016中使用_企业网易邮箱用2016outlook-程序员宅基地

文章浏览阅读1.1k次。Outlook邮箱配置1.2.3.成功之后点击下一步_企业网易邮箱用2016outlook

【MySQL】创建表时主键与外键_表里主键只允许出现一列嘛-程序员宅基地

文章浏览阅读3.3k次。1.什么时候用主键?主键的用处?保证数据的唯一性2.一张表只能有一个主键吗?√3.一个主键只能是一列吗?×---支持多列合起来做主键,即复合主键,只要保证唯一性即可图中1表示用第一列nid做主键,2表示用nid和pid两列合起来做主键,即复合外键(不常用)4.在进行外键关联的时候,如果关联的表的主键是由多列组合而成的,那么在进行外键约束的时候由括号中的两部分一起另外,需要注意外键名不能重复,故在进行外键命名时,比如t2和t1进行外键关联,则命名为fk_t2_t1,若t3和.._表里主键只允许出现一列嘛

Init 进程详解_init进程-程序员宅基地

文章浏览阅读1.1w次。Android 内核加载完成后,就会启动init进程,init进程是Android系统用户空间的第一个进程。init程序放在系统根目录下,init进程代码位于源码的目录“system/core/init”下面。下面我们来分析init进程的启动过程1. 分析入口函数进程init入口函数是main,具体实现文件的路径是: system\core\init\init.c 分析main函数:int ma_init进程

【服务器】服务器 3D组网图_单服务器组网图说明-程序员宅基地

文章浏览阅读1.1k次。参考:http://support.huawei.com/onlinetoolsweb/server-3D/ 服务器3D图参考:http://support-it.huawei.com/server-networking-assistant/#/home刀片服务器组网图_单服务器组网图说明