官网参考:https://dev.mysql.com/doc/refman/5.7/en/blob.htmlhtml
Data Type | Storage Required |
---|---|
CHAR( |
M × w bytes, 0 <= 255, where w is the number of bytes required for the maximum-length character in the character set. See Section 14.8.1.2, “The Physical Row Structure of an InnoDB Table” for information about CHAR data type storage requirements for InnoDB tables. |
BINARY( |
M bytes, 0 <= 255 |
VARCHAR( , VARBINARY( |
L + 1 bytes if column values require 0 − 255 bytes, L + 2 bytes if values may require more than 255 bytes |
TINYBLOB , TINYTEXT |
L + 1 bytes, where L < 28 |
BLOB , TEXT |
L + 2 bytes, where L < 216 |
MEDIUMBLOB , MEDIUMTEXT |
L + 3 bytes, where L < 224 |
LONGBLOB , LONGTEXT |
L + 4 bytes, where L < 232 |
ENUM(' |
1 or 2 bytes, depending on the number of enumeration values (65,535 values maximum) |
SET(' |
1, 2, 3, 4, or 8 bytes, depending on the number of set members (64 members maximum) |
mysql> desc varch -> ; +-------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+------------+------+-----+---------+-------+ | name | varchar(3) | YES | | NULL | | +-------+------------+------+-----+---------+-------+ 1 row in set (0.00 sec) mysql> insert into varch values('hell'); ERROR 1406 (22001): Data too long for column 'name' at row 1 mysql> insert into varch values('hel'); Query OK, 1 row affected (0.00 sec) mysql> select * from varch; +-----------+ | name | +-----------+ | 新中国 | | hel | +-----------+ 2 rows in set (0.00 sec)
mysql> create table varch(name varchar(21845)); 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> create table varch(name varchar(21844)); Query OK, 0 rows affected (0.11 sec)
innodb_page_size
的设置的一半(若是设置不超过32KB,默认是16KB),对于text 和blob 没有限制,只会占用row size 的9-12字节(byte)mysql> create table varch(col1 varchar(10920),col2 varchar(10920),col3 text); Query OK, 0 rows affected (0.12 sec) # 10920 计算公式 mysql> select (65535-(2+2+9))/3/2; +---------------------+ | (65535-(2+2+9))/3/2 | +---------------------+ | 10920.33333333 | +---------------------+ # 括号里的二、2、9是字段的长度存储所需大小
max_sort_length
指定的长度进行,次变量默认值为1024,能够进行session级别的调整SELECT *
max_allowed_packet
进行设置,客户端和服务器端都须要设置