官網參考: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
進行設置,客戶端和服務器端都須要設置