mysql data types
Integer type
tinyint . 1 byte
smallint The 2-byte
MEDIUMINT . 3 bytes
int . 4 bytes
BIGINT . 8 bytes
Commonly used floating-point type
a float . 4 bytes are not accurate
Double . 8 bytes inaccuracy
decimal every four bytes of digital memory 9, the decimal precision of one byte
- 123456789.987654321 = decimal (18,9) occupies 9 bytes
- 1,234,567,894 bytes 9,876,543,214 bytes 1 byte
Common types of time
DATE . 3 byte format: YYYY-MM-DD range: from '1000-01-01' to '9999-12-31'
The TIME 3-6 Byte Format: HH: MM: SS range [sec values.]: From '-838: 59: 59' to '838: 59: 59' can be accessed within a time interval
Microsecond | storage |
---|---|
0 | 0bytes |
1,2 | 1bytes |
3,4 | 2bytes |
5,6 | 3bytes |
YEAR . 1 byte format: YYYY range: from 1901 to 2155
DATETIME 5-8 byte format: YYYY-MM-DD HH: MM: SS range [sec values.]: From "1000-01-0100" 00 o'clock "to" 9999-12-31 23:59: 59 '
TIMESTAMP 4-7 byte format: YYYY-MM-DD HH: MM: SS range [sec values.]: From the '1970-01-01 00:00:01' UTC to '2038-01-19 03:14 : 07 'UTC
Used string type
Char (M) range: M = 1 ~ 255 characters of fixed length
Varchar (M) bytes of all type varchar columns occupied by one line can not exceed 65535 bytes UTF8mb4 varchar (10) = 40 bytes
Storing variable-length character M
TinyText range: a maximum length of 255 bytes of variable length
Text range: The maximum length of a variable length 65535 bytes
MediumText range: The maximum length of a variable length byte 16777215
LongText range: The maximum length of a variable length byte 4294967298
Enum range: the set maximum number of values in the list of only 65535
How to choose the appropriate data type for the data
- Preference smallest data type to store data in line with demand
IP address translation: INET_ATON ( '255.255.255.255') = 4294967295
INET_NTOA (4294967295) = 255,255,255,255 '
- Prudent use ENUM, TEXT TEXT string type enum need not alter the index data generated
- Numerical data associated with finance, you must use the decimal type
How to choose a name for tables and columns
All database object names must be lowercase letters can choose underlined split
All database object names defined prohibit the use Mysql keyword (official website)
Name the database objects to be able to see the name recognition is intended to do, try not to exceed 32 characters
Library tmp temporary table must be prefixed and suffixed by date
Library for backup, bak table must be prefixed and suffixed by date
All the same data is stored out of column names and types must be consistent