Is VARCHAR (20,000) valid in MySQL?

I need some clarification of the maximum length of the varchar field in MySQL.

I always thought that the maximum length is 255 (255 characters), but that could be the source of my confusion). Having looked at the database tables created by an external company, I worked with setting the field as varchar (20000), containing xml pieces longer than 255 characters. Why does it work? Is a value of 20,000 valid?

A little googling showed that in mysql, varchar has a limit of 65,535 bytes, and I see varchar (65535) in use , since the limit of 255 refers to this?

+57
mysql varchar
Aug 20 '09 at 1:17
source share
6 answers

Pay attention to the version of MySQL.

http://dev.mysql.com/doc/refman/5.0/en/char.html

The values ​​in the VARCHAR columns are variable-length rows. The length can be specified as a value from 0 to 255 to MySQL 5.0.3 and from 0 to 65535 in 5.0.3 and later. The effective maximum VARCHAR length in MySQL 5.0.3 and later depends on the maximum row size (65,535 bytes, which is shared between all columns) and the character set used.

What version of MySQL do I have?

Run the following query ...

select version() as myVersion 
+70
Aug 20 '09 at 1:21
source share

This is true from version 5.0.3, when they changed the maximum length from 255 to 65535.

CHAR has always been 255 max.

http://dev.mysql.com/doc/refman/5.0/en/char.html

+12
Aug 20 '09 at 1:19
source share

If you expect too much cost, it is best to use TEXT, MEDIUMTEXT or LONGTEXT.

+6
Aug 20 '09 at 1:19
source share

Although the index cannot be built on varchar (2000)

+2
Sep 27 '09 at 10:56
source share

This question already has an answer to What is the maximum size of MySQL VARCHAR?

Keep in mind that MySQL has a maximum row size limit.

The internal MySQL table view has a maximum row size limit of 65,535 bytes, not counting the BLOB and TEXT types. BLOB and TEXT columns contribute only 9 to 12 bytes to the row size limit, because their contents are stored separately from the rest of the row. Read more about Limitations on the number of column columns and row size .

The maximum size of one column may take, differs before and after MySQL 5.0.3

The values ​​in the VARCHAR columns are variable-length rows. The length can be specified as a value from 0 to 255 to MySQL 5.0.3 and from 0 to 65,535 in 5.0.3 and later. The effective maximum VARCHAR length in MySQL 5.0.3 and later depends on the maximum row size (65,535 bytes, which is shared between all columns) and the character set used.

However, note that the limit is lower if you use a multibyte character set, such as utf8 or utf8mb4.

Use TEXT inorder types to overcome string size limits.

The four types of TEXT are TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT. They correspond to the four BLOB types and have the same maximum length and storage requirements.

+2
Jan 14 '17 at 9:34 on
source share

The MySQL User Guide

The values ​​in the VARCHAR columns are variable-length rows. The length can be specified as a value from 0 to 255 to MySQL 5.0.3 and from 0 to 65535 in versions 5.0.3 and later.

So it depends on the version you are using.

+1
Aug 20 '09 at 1:29
source share



All Articles