The difference between Char,varchar and text types in MySQL

Source: Internet
Author: User

About Char,varchar and text usually do not care too much, in general, probably now everyone is using varchar. But when the content to be stored is larger, what is the choice between varchar or text? I don't know......

text, char, varchar are the data in the database storage policy issues, in order to, reasonable
Application storage space is the way that database server data types are divided. For applications, put them
And the string corresponds to it.

Then went to look up some information, by the way, the three types of comparison:

(1) Char:char Needless to say, it is fixed-length format, but the length range is 0~255. When you want to store a character that is less than 255 long, MySQL fills the remaining characters with a space. Therefore, when reading data, the char type of data to be processed, the following space is removed.

(2) varchar: about varchar, some say the maximum length is 255, also some say 65535, Looking at a lot of data, I found this: the varchar type has a maximum length limit of 255 in versions under 5.0.3, whereas in versions 5.0.3 and above, the varchar data type is supported to 65535, which means it can hold 65,532 bytes (note that bytes are not characters!!!). Data (starting and ending bits take up 3 bytes), that is, in 5.0.3 The data that needs to be stored in a fixed text or BLOB format can be stored in a higher version with variable-length varchar, which effectively reduces the size of the database file.

(3) Text: Unlike char and varchar, text can not have a default value, its maximum length is 2 of 16 square-1

Summing up, there are several points:

    1. frequently changing fields with varchar
    2. Know the fixed length with Char
    3. Try to use varchar.
    4. More than 255 characters can be used only with varchar or text
    5. Where you can use varchar without text.

The difference between Char,varchar and text types in MySQL

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.