A mysql field can contain a maximum of 1000 characters and does not need to be searched. The number of records may exceed 10 million. In the future, it may be horizontally divided into tables. Should it be set to varchar or text? Do you need to split the table vertically? A mysql field can contain a maximum of 1000 characters and does not need to be searched. The number of records may exceed 10 million. In the future, it may be horizontally divided into tables. Should it be set to varchar or text? Do you need to split the table vertically?
Reply content:
A mysql field can contain a maximum of 1000 characters and does not need to be searched. The number of records may exceed 10 million. In the future, it may be horizontally divided into tables. Should it be set to varchar or text? Do you need to split the table vertically?
The length of the mysql record row is limited, not infinite. The length is 64 KB, that is, 65535 bytes, which is the same for all tables.
MySQL has 1-2 bytes for variable-length fields to store the character length.
When the number of characters is less than or equal to 255, MySQL only uses one byte for recording, because the power of 2 minus 1 can only be saved to 255.
When the number of characters exceeds 255, the length must be 2 bytes.
Varchar in UTF-8 state, up to (65535-2)/3 = 21844 + 1.
Varchar in gbk status, up to (65535-2)/2 = 32766 + 1
Reference: https://ruby-china.org/topics/24920
The length of 1000 is very common and does not need to be split into tables in most cases. Text is not required. Use varchar directly.
In mysql versions later than mysql 5.5, varchar does not have field length restrictions. However, it should be noted that the full row record has a limit of 65535 bytes (in bytes, not characters. In case of UTF-8 encoding, a single character may take 2-3 bytes ).
Record records of tens of millions of records are even better. When reading and writing is very frequent and the performance is very strict, this field should be separated.
VARCHAR () can only store text at a maximum of 255