Whether the varchar length in MySQL is a byte or a character

Source: Internet
Author: User

Today in the design of the table, there is a small problem, because do not know how long the future will be stored data (data is provided through the third-party HTTP interface, according to sample display, the data is probably as follows:)

That is, 6 characters.

When I was designing the table, I hesitated, and was prepared to design varchar (6), but the fear was that it would be a byte-count, which would lead to a deposit. (Database with UTF8 encoding)

So I tried it myself,

Can hold 5 UTF8 characters. It seems that MySQL's varchar is calculated according to the characters.

And then look at the answers on the Web:

That is, before version4, by byte;

After Version5, press the character.

Whether the varchar length in MySQL is a byte or a character

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.