mysql optimized field selection

int lot selection
write picture description here

Fixed length field
varchar (length) 1~65535 bytes
Content range: 65535 single-byte contents, the contents should be saved 1~2 bytes, and the length of the contents should be saved.
utf-8 character set 3 bytes one Chinese character: 1~20000 Chinese characters
char (length) 1~255 characters.
Single byte: each byte is equal to 1 character
Chinese character : 3 bytes are equal to one character
No matter the single-byte content, Chinese characters can store 1~255
chars, and the running speed is fast, for example: char(20), if the actual Store 16 characters, or allocate 20 spaces
varchar() runs a little slower, for example, varchar(20) actually stores 16 characters and allocates 16 spaces. It
is best to fix the length of the content.
Mobile phone number: char(11)

time type

Time becomes integer storage:
int
date , time , datetime , timestamp
Collection: set('basketball','volleyball','football','baseball')
enumeration: enum('male','female','secret ') It is
recommended to use collection and enumeration types. The integers used internally by them to store
IP addresses can also be converted to integer storage: inet_aton(ip) inet_ntoa(number)

mysql> select inet_aton('192.168.31.53');
+----------------------------+
| inet_aton('192.168.31.53') |
+----------------------------+
|                 3232243509 |
+----------------------------+
1 row in set (0.00 sec)

mysql> select inet_ntoa(3232243509)
    -> ;
+-----------------------+
| inet_ntoa(3232243509) |
+-----------------------+
| 192.168.31.53         |
+-----------------------+
1 row in set (0.00 sec)

myisam: writing data is very fast, suitable for systems with many write and read operations
innodb: suitable for systems with strong business logic

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325786268&siteId=291194637