https://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html 给出了 5.6 版本的限制。注意,不同版本 MySQL 的限制可能略有不同。
这里列出 InnoDB 存储引擎的部分限制:
innodb_large_prefix
,一列能索引的字节不能超过 3072 。 innodb_large_prefix
默认未启用。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 BLOBs
latin1 字符集中每个字符1字节。根据报错信息,可以看出 65535 的限制是在去除 TEXT、BLOB 之后。所以下面的不会报错:
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)
create table test_table (
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)
) engine = InnoDB character set = utf8mb4;
表创建成功,使用 utf8mb4 字符集。
插入数据:
-- @you255 含有255个'你'
set @you255 = '你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你你'
insert into test_table (c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14) values(
@you255, @you255, @you255, @you255, @you255, @you255, @you255, @you255, @you255, @you255, @you255, @you255, @you255, @you255
)
报错:
(1118, u'Row size too large (> 8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. In current row format, BLOB prefix of 768 bytes is stored inline.')
SHOW TABLE STATUS
给出的信息是不精确的。SELECT COUNT(*)
查询得到。( 本文完 )