Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the MySQL VARCHAR max size?

I would like to know what the max size is for a MySQL VARCHAR type.

I read that the max size is limited by the row size which is about 65k. I tried setting the field to varchar(20000) but it says that that's too large.

I could set it to varchar(10000). What is the exact max I can set it to?

like image 696
user1832628 Avatar asked Nov 22 '12 06:11

user1832628


People also ask

What is the max limit of VARCHAR?

varchar [ ( n | max ) ] Use n to define the string size in bytes and can be a value from 1 through 8,000, or use max to indicate a column constraint size up to a maximum storage of 2^31-1 bytes (2 GB).

Is VARCHAR max 255?

VARCHAR(255) stores 255 characters, which may be more than 255 bytes.

Can I use VARCHAR 1000?

The maximum key length is 1000 bytes. This can also be changed by changing the source and recompiling. For the case of a key longer than 250 bytes, a larger key block size than the default of 1024 bytes is used. As an index is created for the key and as it is working without an index, this makes sense.

How long is VARCHAR 256?

TEXT and BPCHAR types You can create an Amazon Redshift table with a TEXT column, but it is converted to a VARCHAR(256) column that accepts variable-length values with a maximum of 256 characters.


1 Answers

Keep in mind that MySQL has a maximum row size limit

The internal representation of a MySQL table has a maximum row size limit of 65,535 bytes, not counting BLOB and TEXT types. BLOB and TEXT columns only contribute 9 to 12 bytes toward the row size limit because their contents are stored separately from the rest of the row. Read more about Limits on Table Column Count and Row Size.

Maximum size a single column can occupy, is different before and after MySQL 5.0.3

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.

However, note that the limit is lower if you use a multi-byte character set like utf8 or utf8mb4.

Use TEXT types inorder to overcome row size limit.

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

More details on BLOB and TEXT Types

  • Ref for MySQLv8.0 https://dev.mysql.com/doc/refman/8.0/en/blob.html
  • Ref for MySQLv5.7 https://dev.mysql.com/doc/refman/5.7/en/blob.html
  • Ref for MySQLv5.6 https://dev.mysql.com/doc/refman/5.6/en/blob.html

Even more

Checkout more details on Data Type Storage Requirements which deals with storage requirements for all data types.

like image 85
rajukoyilandy Avatar answered Sep 19 '22 17:09

rajukoyilandy