MySQL data types include
1. Integer type, floating-point type, and fixed-point number type
2. Time and Date type
3. String type
4. Binary type
Integer type
Standard SQL supports integer,smallint these two types of integers, MySQL in addition to these two there are other, see the table below
type |
size |
Range (signed) |
range (unsigned) |
default width |
TINYINT |
1 bytes |
( -128,127) |
(0,255) |
4 |
SMALLINT |
2 bytes |
( -32 768,32 767) |
(0,65 535) |
6 |
mediumint |
3 bytes |
( -8 388 608,8 388 607) |
(0,16 777 215) |
8 |
int or integer |
4 bytes |
( -2 147 483 648,2 147 483 647) |
(0,4 294 967 295) |
one |
BIGINT |
8 bytes /td> |
( -9 233 372 036 854 775 808,9 223 372 036 854 775 807) |
(0,18 446 744 073 709 551 615) |
20 /td> |
The number of bytes and the range of values for int and integer are the same, in fact, the int and the integer types are the same in MySQL
Why the unsigned range of tinyint is (0,255), because tinyint is 1 bytes and 1 bytes is 8 bits, then the maximum value of tinyint unsigned number is 28-1, that is, the maximum number of 255,tinyint signed is 27-1, or 127.
The same is true of other types.
MySQL support data type name is followed by the width, its basic form is data type (width value)
Q: Why is the default width of tinyint 4 instead of 3 and the maximum value is 255?
A: If it is a signed case, there will be a value of-128, and its width is 4.
MySQL Data type detailed