对于MySql 8.0版 .
数字类型存储要求
Data Type Storage Required
TINYINT 1 byte
SMALLINT 2 bytes
MEDIUMINT 3 bytes
INT, INTEGER 4 bytes
BIGINT 8 bytes
FLOAT(p) 4 bytes if 0 <= p <= 24, 8 bytes if 25 <= p <= 53
FLOAT 4 bytes
DOUBLE, REAL 8 bytes
DECIMAL(M,D), NUMERIC(M,D) Varies; see following discussion
BIT(M) approximately (M+7)/8 bytes
DECIMAL(和NUMERIC)列的值使用二进制格式表示,该格式将九个十进制(基数10)数字打包成四个字节 . 每个值的整数和小数部分的存储是分开确定的 . 九个数字的每个倍数需要四个字节,“剩余”数字需要四个字节的一小部分 . 超出数字所需的存储量由下表给出 .
日期和时间类型存储要求对于TIME,DATETIME和TIMESTAMP列,在MySQL 5.6.4之前创建的表所需的存储与从5.6.4创建的表不同 . 这是由于5.6.4中的更改允许这些类型具有小数部分,这需要0到3个字节 .
Data Type Storage Required Before MySQL 5.6.4 Storage Required as of MySQL 5.6.4
YEAR 1 byte 1 byte
DATE 3 bytes 3 bytes
TIME 3 bytes 3 bytes + fractional seconds storage
DATETIME 8 bytes 5 bytes + fractional seconds storage
TIMESTAMP 4 bytes 4 bytes + fractional seconds storage
从MySQL 5.6.4开始,YEAR和DATE的存储保持不变 . 但是,TIME,DATETIME和TIMESTAMP的表示方式不同 . DATETIME打包效率更高,非分数部分需要5个而不是8个字节,并且所有三个部分都有一个小数部分,需要0到3个字节,具体取决于存储值的小数秒精度 .
Fractional Seconds Precision Storage Required
0 0 bytes
1, 2 1 byte
3, 4 2 bytes
5, 6 3 bytes
例如,TIME(0),TIME(2),TIME(4)和TIME(6)分别使用3,4,5和6个字节 . TIME和TIME(0)是等效的,需要相同的存储空间 .
有关时间值的内部表示的详细信息,请参阅MySQL内部:重要算法和结构 .
字符串类型存储要求在下表中,M表示非二进制字符串类型的声明列长度,以及二进制字符串类型的字节 . L表示给定字符串值的实际长度(以字节为单位) .
Data Type Storage Required
CHAR(M) The compact family of InnoDB row formats optimize storage for variable-length character sets. See COMPACT Row Format Characteristics. Otherwise, M × w bytes, <= M <= 255, where w is the number of bytes required for the maximum-length character in the character set.
BINARY(M) M bytes, 0 <= M <= 255
VARCHAR(M), VARBINARY(M) 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('value1','value2',...) 1 or 2 bytes, depending on the number of enumeration values (65,535 values maximum)
SET('value1','value2',...) 1, 2, 3, 4, or 8 bytes, depending on the number of set members (64 members maximum)