MySQL VARCHAR size?

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

+43
mysql varchar
Aug 19 '11 at 15:38
source share
3 answers

100 characters.

This is var (variable) in varchar : you only save what you type (and an extra 2 bytes for storing lengths up to 65535)

If it was char(200) then you should always keep 200 characters filled with 100 spaces

See documents: Types CHAR and VARCHAR

+64
Aug 19 '11 at 15:40
source share
โ€” -

VARCHAR means it is a variable-length character, so it takes up as much space as necessary. But if you knew something about the underlying structure, it might make sense to limit VARCHAR to some maximum amount.

For example, if you save comments from the user, you can limit the comment field to only 4000 characters; if so, then it doesnโ€™t really make sense to make the sql table a field that is larger than VARCHAR (4000).

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

+7
Aug 19 '11 at 15:41
source share

Actually, it will take 101 bytes.

MySQL Reference

+4
Jan 02 '15 at 9:10
source share



All Articles