Summary of char,varchar,text differences in MySQL

Source: Internet
Author: User
Tags truncated

You can view the MySQL Help documentation in detail for these three types of instructions.

A summary of Char:
The maximum length of char is 255 characters, note that the character number and character set do not matter. There can be default values, and trailing spaces are truncated.
Summary of varchar:
The maximum length of varchar 65535 refers to the number of bytes that can be stored, in fact, up to 65,532 bytes, and 3 bytes for storage length. Note that the number of bytes is related to the character set . A kanji character occupies 3 bytes with UTF8 and 2 bytes in GBK. There can be default values, and trailing spaces are not truncated.
Summary of text:
Text and varchar are basically the same. Text ignores the specified size this differs from varchar, where text cannot have a default value. The trailing spaces are not truncated. Text uses an extra 2 bytes to store the size of the data, and varchar chooses a few bytes to store the size of the data. The 65535 bytes of text are all used to store data, and varchar consumes 1-3 bytes to store the data size.
Everything mentioned above is for MySQL only, and the other databases may be different. Please point out where there is something wrong.

------------------------------------------------------------------

1. varchar to a certain length will automatically convert to text

2. Can be done with varchar, absolutely no text, otherwise performance is much worse

3. For the article content and so on a kind of thing, have no choice, can only use text, for this suggestion must disassemble the storage ...

Summary of char,varchar,text differences in MySQL

Related Article

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.