MySQL Char varchar two or three thing

Source: Internet
Author: User

MySQL char and varchar are very similar.

The maximum length of char is 255, and when it is not enough 255 characters, the right side complements the spaces padding.

The maximum varchar length is 65535.

VARCHAR (n) has one or two bytes more than char (n), which is used to determine the length of the varchar value. When value does not exceed 255 characters, an additional byte is required. When value exceeds 255 characters, 2 bytes are required.

Query efficiency comparison: Because varchar needs to position the length of value based on additional bytes, it is slower than char.

The row contains varchar and char cases Query efficiency
Contains char and varchar Low
Contains only varchar Low
Contains only Char High

CHAR (10) fills ' 1234567890 ', char (10) occupies 10 characters instead of 10 bytes. The specific occupancy byte is determined by the database collation set.

The difference between varchar (10) and varchar (255): When only one ' a ' is written, varchar (255) assigns 255 characters when the query requires a temporary table. VARCHAR (10) assigns only 10 characters.

MySQL Char varchar two or three thing

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.