1. Numeric types

1, int type 4 bytes. Note: A byte has 8 bits, that is, 32 bits and one sign bit. So the number that can be stored is from minus two to the thirty-first to two to the thirty-first;

2. The type of tinyint is 1 byte.

3. Smallint Specifies the type of 2 bytes

4. Mediumint: 3 bytes

5. Bigint is 8 bytes

6, float type 4 bytes single-precision floating point number

7, type double 8-byte double floating-point number

Note: Float single precision significant is 7 bits, double double significant is 16 bits.

A double takes up twice as much memory as a float, so a float is faster, so use float whenever possible.

2. String type

Char type M bytes, 1 <= M <= 255

Varchar type L+1 bytes, where L <= M and 1 <= M <= 255

Text type L+2 bytes, where L< 2 ^ 16

Remark:

(1) Char is a fixed length, such as 10. If I save ABC, it’s still going to take up 10.

Varchar is a variable length, and it takes up a space of 3. When obtaining data, varchar does not need to remove the following Spaces.

(2) Char access degree is much faster than VARCHar, because its length is fixed, convenient program storage and search; However, CHAR also pays the price of space, because its length is fixed, so there will inevitably be extra space placeholders to occupy the space. It can be said that space is exchanged for time efficiency, while Varchar takes space efficiency as the first place.

(3) The storage mode of char is 1 byte for English characters (ASCII) and 2 bytes for a Chinese character; Varchar, on the other hand, takes up 2 bytes for each English character and 2 bytes for each Chinese character, both of which are non-Unicode character data.