What is the maximum length of mysqlVARCHAR? _ MySQL

Source: Internet
Author: User
What is the maximum length of mysqlVARCHAR bitsCN.com?
What is the maximum length of mysql VARCHAR? someone asked in the group today: Is it possible to set the maximum length of varchar to 65532 (the first byte + two length byte, but why is it possible to set it to 65533? we always thought that there are two bytes to record the length (the length is small or one byte can be used ), this problem was boring at the time, but some people in the group explained it and suddenly found that it was not such a simple mysql compact format, each record has one byte to indicate the distribution of NULL fields. if any field in the table is allowed to be NULL, the maximum value can be set to 65532. If no field is allowed to be NULL, the byte can be saved, it can be defined as 65533 at most. I don't know if this is the reason. so I read some documents online and did some experiments locally, in the past, the maximum length of vachar was really variable (determined based on whether there are non-empty fields). In this experiment, innodb + latin environment 1 -- success2drop table if exists test; 3 create table test (name varchar (65533) not null) engine = innodb default charset = latin14 5 -- too large6drop table if exists test; 7
Create table test (name varchar (65533) engine = innodb default charset = latin1 in the second case, when a blank field is allowed, the length cannot be increased to 65533, and the maximum value is 65532, it should be the quote.
Some people have done similar experiments on the Internet, refer to http://stackoverflow.com/questions/8295131/best-practise-for-sql-varchar-column-length 1 name varchar (100) not null will be 1 byte (length) + up to 100 chars (latin1) 2 3 name varchar (500) not null will be 2 bytes (length) + up to 500 chars (latin1) 4 5 name varchar (65533) not null will be 2 bytes (length) + up to 65533 chars (latin1) 6 7 name varchar (65532) will be 2 bytes (length) + up 65532 chars (latin1) + 1 null byte to sum up, the original mysql vachar field type although the maximum length is 65535, but not can store so much data, it can be up to 65533 (when non-empty fields are not allowed), and only 65532 can be allowed when non-empty fields are allowed.
BitsCN.com

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.