A mysql field is 1000 characters long and does not need to be used for search. Is it set to varchar or text for massive data?

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.