Limits on Table Column Count and Row Size Databases and Tables Table Size 最大行数
MySQL :: MySQL 8.0 Reference Manual :: C.10.4 Limits on Table Column Count and Row Size https://dev.mysql.com/doc/refman/8.0/en/column-count-limit.html
C.10.4 Limits on Table Column Count and Row Size
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. SeeRow 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.8, “Data Type Storage Requirements”.
Storage engines may impose additional restrictions that limit table column count. For example,
InnoDBhas a limit of 1017 columns per table. SeeSection 15.6.1.7, “Limits on InnoDB Tables”. For information about other storage engines, see Chapter 16, Alternative Storage Engines.Functional key parts (see Section 13.1.15, “CREATE INDEX Syntax”) are implemented as hidden virtual generated stored columns, so each functional key part in a table index counts against the table total column limit.
Row Size Limits
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.
BLOBandTEXTcolumns 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
InnoDBtable, which applies to data stored locally within a database page, is slightly less than half a page for 4KB, 8KB, 16KB, and 32KBinnodb_page_sizesettings. For example, the maximum row size is slightly less than 8KB for the default 16KBInnoDBpage size. For 64KB pages, the maximum row size is slightly less than 16KB. See Section 15.6.1.7, “Limits on InnoDB Tables”.If a row containing variable-length columns exceeds the
InnoDBmaximum row size,InnoDBselects variable-length columns for external off-page storage until the row fits within theInnoDBrow 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 15.10, “InnoDB Row Storage and 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
InnoDBrow formats, see Section 15.10, “InnoDB Row Storage and Row Formats”, and Section 15.6.1.2, “The Physical Row Structure of an InnoDB Table”.For information about
MyISAMstorage formats, see Section 16.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
InnoDBandMyISAMexamples. 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 BLOBsmysql> 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 BLOBsIn the following
MyISAMexample, changing a column toTEXTavoids the 65,535-byte row size limit and permits the operation to succeed becauseBLOBandTEXTcolumns 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
InnoDBtable because changing a column toTEXTavoids the MySQL 65,535-byte row size limit, andInnoDBoff-page storage of variable-length columns avoids theInnoDBrow 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 utf8mb3column takes two bytes to store the length of the value, so each value can take up to 767 bytes.The statement to create table
t1succeeds 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
t2fails 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 BLOBsReducing 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
MyISAMtables,NULLcolumns require additional space in the row to record whether their values areNULL. EachNULLcolumn takes one bit extra, rounded up to the nearest byte.The statement to create table
t3fails becauseMyISAMrequires space forNULLcolumns 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 BLOBsFor information about
InnoDBNULLcolumn storage, see Section 15.6.1.2, “The Physical Row Structure of an InnoDB Table”.InnoDBrestricts 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_sizesettings, and to slightly less than 16KB for 64KB pages.The statement to create table
t4fails because the defined columns exceed the row size limit for a 16KBInnoDBpage.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=DYNAMIC DEFAULT CHARSET latin1;
ERROR 1118 (42000): Row size too large (> 8126). Changing some columns to TEXT or BLOB may help.
In current row format, BLOB prefix of 0 bytes is stored inline.
MySQL :: MySQL 8.0 Reference Manual :: C.10.2 Limits on Number of Databases and Tables https://dev.mysql.com/doc/refman/8.0/en/database-count-limit.html
C.10.2 Limits on Number of Databases and Tables
MySQL has no limit on the number of databases. The underlying file system may have a limit on the number of directories.
MySQL has no limit on the number of tables. The underlying file system may have a limit on the number of files that represent tables. Individual storage engines may impose engine-specific constraints. InnoDB permits up to 4 billion tables.
MySQL :: MySQL 8.0 Reference Manual :: C.10.3 Limits on Table Size https://dev.mysql.com/doc/refman/8.0/en/table-size-limit.html
C.10.3 Limits on Table Size
The effective maximum table size for MySQL databases is usually determined by operating system constraints on file sizes, not by MySQL internal limits. For up-to-date information operating system file size limits, refer to the documentation specific to your operating system.
Windows users, please note that FAT and VFAT (FAT32) are not considered suitable for production use with MySQL. Use NTFS instead.
If you encounter a full-table error, there are several reasons why it might have occurred:
The disk might be full.
You are using
InnoDBtables and have run out of room in anInnoDBtablespace file. The maximum tablespace size is also the maximum size for a table. For tablespace size limits, see Section 15.6.1.7, “Limits on InnoDB Tables”.Generally, partitioning of tables into multiple tablespace files is recommended for tables larger than 1TB in size.
You have hit an operating system file size limit. For example, you are using
MyISAMtables on an operating system that supports files only up to 2GB in size and you have hit this limit for the data file or index file.You are using a
MyISAMtable and the space required for the table exceeds what is permitted by the internal pointer size.MyISAMpermits data and index files to grow up to 256TB by default, but this limit can be changed up to the maximum permissible size of 65,536TB (2567 − 1 bytes).If you need a
MyISAMtable that is larger than the default limit and your operating system supports large files, theCREATE TABLEstatement supportsAVG_ROW_LENGTHandMAX_ROWSoptions. See Section 13.1.20, “CREATE TABLE Syntax”. The server uses these options to determine how large a table to permit.If the pointer size is too small for an existing table, you can change the options with
ALTER TABLEto increase a table's maximum permissible size. See Section 13.1.9, “ALTER TABLE Syntax”.ALTER TABLE tbl_name MAX_ROWS=1000000000 AVG_ROW_LENGTH=nnn;You have to specify
AVG_ROW_LENGTHonly for tables withBLOBorTEXTcolumns; in this case, MySQL can't optimize the space required based only on the number of rows.To change the default size limit for
MyISAMtables, set themyisam_data_pointer_size, which sets the number of bytes used for internal row pointers. The value is used to set the pointer size for new tables if you do not specify theMAX_ROWSoption. The value ofmyisam_data_pointer_sizecan be from 2 to 7. A value of 4 permits tables up to 4GB; a value of 6 permits tables up to 256TB.You can check the maximum data and index sizes by using this statement:
SHOW TABLE STATUS FROM db_name LIKE 'tbl_name';You also can use myisamchk -dv /path/to/table-index-file. See Section 13.7.6, “SHOW Syntax”, or Section 4.6.4, “myisamchk — MyISAM Table-Maintenance Utility”.
Other ways to work around file-size limits for
MyISAMtables are as follows:If your large table is read only, you can use myisampack to compress it. myisampack usually compresses a table by at least 50%, so you can have, in effect, much bigger tables. myisampack also can merge multiple tables into a single table. See Section 4.6.6, “myisampack — Generate Compressed, Read-Only MyISAM Tables”.
MySQL includes a
MERGElibrary that enables you to handle a collection ofMyISAMtables that have identical structure as a singleMERGEtable. See Section 16.7, “The MERGE Storage Engine”.
You are using the
MEMORY(HEAP) storage engine; in this case you need to increase the value of themax_heap_table_sizesystem variable. See Section 5.1.8, “Server System Variables”.
最大行数
如果主键为整数id,则受限于
MySQL :: MySQL 8.0 Reference Manual :: 11.2.1 Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
Table 11.1 Required Storage and Range for Integer Types Supported by MySQL
| Type | Storage (Bytes) | Minimum Value Signed | Minimum Value Unsigned | Maximum Value Signed | Maximum Value Unsigned |
|---|---|---|---|---|---|
TINYINT |
1 | -128 |
0 |
127 |
255 |
SMALLINT |
2 | -32768 |
0 |
32767 |
65535 |
MEDIUMINT |
3 | -8388608 |
0 |
8388607 |
16777215 |
INT |
4 | -2147483648 |
0 |
2147483647 |
4294967295 |
BIGINT |
8 | -263 |
0 |
263-1 |
264-1 |
字段类型
CREATE TABLE `testtab` (
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1000000000 DEFAULT CHARSET=utf8;
2**(1*8)= 256
2**(2*8)= 65536
2**(3*8)= 16777216
2**(4*8)= 4294967296
2**(8*8)= 18446744073709551616
0、可存储的数据范围确定,基于8byte,2**32,和是否有正负符号有关;
1、当设置填充0时
1、1自动转换为无符号型;
If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column.
1、
int(2) int(11) 为 最小显示宽度;
【数值位数未达到设置的显示宽度时,会在数值前面补充零直到满足设定的显示宽度,为什么会有无符号的限制呢,是因为ZEROFILL属性会隐式地将数值转为无符号型,因此不能存储负的数值。】
「MYSQL」MYSQL中的int(11)到底代表什么意思? - Jchermy的前端之路 - SegmentFault 思否 https://segmentfault.com/a/1190000012479448
Limits on Table Column Count and Row Size Databases and Tables Table Size 最大行数的更多相关文章
- “ORA-01747: user.table.column, table.column 或列说明无效” 的解决方案
此问题的原因是因为表的列名称使用了Oracle声明的关键字,列名起的不好引起的. 如果列很多,又不好确定是哪个列名使用了关键字,以下建议可供参考: select * from v$reserved_w ...
- (转载)MySQL 统计数据行数 Select Count
(转载)http://www.5idev.com/p-php_mysql_select_count.shtml 统计数据行数 SELECT COUNT() FROM 语法用于从数据表中统计数据行数. ...
- 开发中运行mysql脚本,发现提示mysql提示Column count doesn't match value count at row 1错误
开发中运行mysql脚本,发现提示mysql提示Column count doesn't match value count at row 1错误, 调试后发现是由于写的SQL语句里列的数目和后面的值 ...
- mysql提示Column count doesn't match value count at row 1错误
mysql提示Column count doesn't match value count at row 1错误,后来发现是由于写的SQL语句里列的数目和后面的值的数目不一致, 比如insert in ...
- [Err] 1136 - Column count doesn't match value count at row 1
1 错误描述 [Err] 1136 - Column count doesn't match value count at row 1 Procedure execution failed 1136 ...
- java.sql.SQLException:Column count doesn't match value count at row 1
1.错误描述 java.sql.SQLException:Column count doesn't match value count at row 1 2.错误原因 在插入数据时,插入的字段 ...
- sql语句出错:Column count doesn't match value count at row 1
报错内容: java.sql.SQLException: Column count doesn't match value count at row 1 at com.mysql.jdbc.SQLEr ...
- mysql Column count doesn't match value count at row 1
今天执行批量插入的操作,发现报了错 mysql Column count doesn't match value count at row 1. 后来发现原因:是由于写的SQL语句里列的数目和后面的值 ...
- 报错:Column count doesn't match value count at row 1
mysql错误:Column count doesn't match value count at row 1 意思是存储的数据与数据库表的字段类型定义不相匹配. 解决办法:检查段类型是否正确, 是否 ...
随机推荐
- 每日英语:The First Day On A Job Is Tough Work
Why is the first day on the job often the worst? New employees tend to be greeted with stacks of ben ...
- dp之完全背包poj1787(完全背包以及路径记录 推荐)
题意:有四种硬币,1分,5分,10分,25分,分别有a,b,c,d种,给出一个n分钱,要求你求出组成n分钱最多需要的硬币数量,并且输出组成它的各种硬币的数量...... 学到的东西:这个题目我是用两种 ...
- MySQL 找回密码
Windows: 1.关闭正在运行的MySQL. 2.打开DOS窗口,转到mysql\bin目录. 3.输入mysqld --skip-grant-tables回车.如果没有出现提示信息,那就对了. ...
- C语言 · c++_ch02_01(打印元音字母的ASCII码)
算法提高 c++_ch02_01 时间限制:1.0s 内存限制:512.0MB 编写一个程序,利用强制类型转换打印元音字母大小写10种形式的ASCII码. 输出的顺序为:大写的字母A ...
- 16c554 的头文件
//------------------------------------------------------------------------------ #ifndef AT16C554H # ...
- php常用的正则表达式
1. 平时做网站经常要用正则表达式,下面是一些讲解和例子,仅供大家参考和修改使用:2. "^\d+$" //非负整数(正整数 + 0)3. "^[0-9]*[1-9][0 ...
- Farey Sequence(欧拉函数)
题意:给出式子F F中分子分母互质,且分子小于分母 例: F2 = {1/2} F3 = {1/3, 1/2, 2/3} F4 = {1/4, 1/3, 1/2, 2/3, 3/4} F5 = {1/ ...
- log4cplus基本用法
说起日志系统,不得不提大名鼎鼎的Log4j.特别是使用Java的人们,能够说是无人不知无人不晓无人不用. Log4j以其简单的使用方式(引入一个jar包.一行代码就可以调用).灵活(可通过配置文件任意 ...
- linux使用ip能ping通,但使用域名却不能访问的解决方法
使用命令:yum -y update进行更新测试,一般测试结果为couldn't resolve hostmirrors.aliyun.com 解决方式参考博客couldn't resolve hos ...
- 在函数体的“出口处”,对 return 语句的正确性和效率进行检查
在函数体的“出口处”,对 return 语句的正确性和效率进行检查. 如果函数有返回值,那么函数的“出口处”是 return 语句. 我们不要轻视 return 语 句.如果 return 语句写得不 ...