The difference between char and varchar in MySQL

Source: Internet
Author: User

CHAR (13) fixed length, as long as the maximum length of not more than 13, the amount of storage space will not change, is always 13, the shortage is supplemented with empty characters.

PS: The required storage space is also a one-time allocation by the database, so at a faster speed than varchar, and there is no fragmentation, but because of the length of fixed also easier to create a waste of storage space, it is generally used to store fixed-length content. such as: MD5 hash value

varchar (13) is variable in length, and its storage space varies depending on the size of the storage content, without exceeding the maximum lengths.

Ps:varchar will use more bytes to store the length information, when it changes the length of the data before and after the database needs to do additional operations, depending on the storage engine, some use a split mechanism, some use paging mechanism, and inevitably produce fragments, the administrator can only import and export jobs to clear the fragmentation.

The difference between char and varchar 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.