Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a VARCHAR(20000) valid in MySQL?

Tags:

mysql

varchar

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

I’ve always thought the max length was 255 (255 what? Characters I’ve assumed, but this might be a source of my confusion). Taking a look at the tables of a database set up by an external company we’re working with, I see a field set-up as varchar(20000), holding chunks of xml longer than 255 characters. Why does this work? Is 20000 a valid value?

A bit of googling has revealed that in mysql varchar has a limit of 65,535 bytes, and I see varchar(65535) in use, so how does the 255 limit relate to this?

like image 499
Zoe Avatar asked Aug 20 '09 01:08

Zoe


People also ask

What is the limit of VARCHAR in MySQL?

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

What is the limit for VARCHAR?

The size of the maximum size (m) parameter of a VARCHAR column can range from 1 to 255 bytes. If you are placing an index on a VARCHAR column, the maximum size is 254 bytes. You can store character strings that are shorter, but not longer, than the m value that you specify.

What does VARCHAR 20 mean in MySQL?

@NIMISHAN (20) is the length of string you will be inserting in the table. suppose social security number is of 9 digit, therefore its length is 9 and it can be easily put in column of datatype VARCHAR(20), but it will cause error in VARCHAR(2)

Does VARCHAR size matter MySQL?

Yes, is matter when you indexing multiple columns. Prefixes can be up to 1000 bytes long (767 bytes for InnoDB tables). Note that prefix limits are measured in bytes, whereas the prefix length in CREATE TABLE statements is interpreted as number of characters.


1 Answers

Note the MySQL Versions.

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

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.

What version of MySQL do I have?

Run the following query...

select version() as myVersion 
like image 138
Sampson Avatar answered Sep 21 '22 23:09

Sampson