Integer type of MySQL data type

Time:2020-11-23

You can use tinyint, smallint, mediumint, int, bigint to store integers in MySQL. They use 8, 16, 24, 32, 64 bit storage space, respectively. The integer type can select the unseigned attribute, which means that negative values are not allowed and represents an unsigned number. This can roughly double the upper limit of the integer. Signed and unsigned types use the same storage space and have the same performance. The following table shows the size and range of different data types, which we can refer to when designing data tables.

type size Range (signed) Range (no sign)
TINYINT 1 byte (-128,127) (0,255)
SMALLINT 2 bytes (-32 768,32 767) (0,65 535)
MEDIUMINT 3 bytes (-8 388 608,8 388 607) (0,16 777 215)
INT 4 bytes (-2 147 483 648,2 147 483 647) (0,4 294 967 295)
BIGINT 8 bytes (-9 233 372 036 854 775 808,9 223 372 036 854 775 807) (0,18 446 744 073 709 551 615)

MySQL can specify the width for integer types, such as int (11), which is meaningless for most applications: it does not limit the legal range of values, but specifies some interactive tools of MySQL, such as MySQL command-line client, to display the number of characters. For storage and operation, int (1) and int (28) are the same.

This work adoptsCC agreementThe author and the link to this article must be indicated in the reprint