Is it possible to declare a VARCHAR with a value greater than 255 in MySQL?

I just noticed in the documentation that in versions greater than MySQL 5.0.3, you can declare varchar with larger values ​​than 255. In the past I switched data types to something larger than 255, but I wonder if it is better it is now practicing defining large string values ​​using varchar (1000) or any other length.

Is this common with other databases now, or is it best to stick to 255 as the maximum value and change data types above that?

+7
source share
3 answers

As pointed out by @Eric's answer, VARCHARs are stored in a table, while TEXTs are stored in a separate file - the only important thing you should keep in mind when designing the table structure is the row size limit (MySQL limits each row / record to 65 KB).

I suggest using VARCHAR for "single-line" - everything that has text input as a data source.

+4
source

In my opinion, I would not want to come up. If you need more than 255 characters, use another TEXT option.

Update: VARCHAR is now limited to 65535 bytes, but a string in MySQL cannot contain more than 65535 bytes.

You should know that VARCHAR and similar fields are stored directly in your database, when, for example, TEXT is stored, print a line followed by a pointer inside the line that refers to it.

So, if you want to use a large VARCHAR, make sure that they will not be too large and will not interfere with the rest of the data in the row.

For example, having mutltiple VARCHAR fields that can contain up to 65K char would be a bad idea.

+6
source

The VARCHAR column is limited to 65,535 bytes, which does not always mean 65,535 characters, depending on which character set you use.

If you use the latin1 character latin1 , which is one byte per character, you will not run into any problems because the length of the string matches the amount of storage required.

If you use a character set that stores multibyte characters, you can only set the length that the character set will allow. For example, the utf8 character set can have a maximum length of 21,844 characters.

+5
source

All Articles