Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL VARCHAR size?

Tags:

mysql

varchar

If I have a VARCHAR of 200 characters and that I put a string of 100 characters, will it use 200 bytes or it will just use the actual size of the string?

like image 222
SBSTP Avatar asked Aug 19 '11 15:08

SBSTP


People also ask

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.

Is VARCHAR a 255?

The varchar, or variable length character field, is the most frequently used field type for storing text less than 256 characters in length.

What size should a VARCHAR be?

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.

Can VARCHAR store more than 255 characters?

3, a VARCHAR could only store up to 255 characters. To store up to 65535 (64KB) characters, use a TEXT column. To store up to 16777216 (16MB ) characters, use a MEDIUMTEXT column. To store up to 4294967296 (4GB) characters, use a LONGTEXT column.


Video Answer


1 Answers

100 characters.

This is the var (variable) in varchar: you only store what you enter (and an extra 2 bytes to store length upto 65535)

If it was char(200) then you'd always store 200 characters, padded with 100 spaces

See the docs: "The CHAR and VARCHAR Types"

like image 123
gbn Avatar answered Oct 04 '22 18:10

gbn