Page 1 of 1
differences between data types of text, char and varchar
Posted: Mon Aug 29, 2005 5:53 am
by aaaphp000000
could u tell me the differences between data types of text, char and varchar?
i focus on size of each type used.
thanks
Posted: Mon Aug 29, 2005 6:13 am
by Chris Corbyn
http://dev.mysql.com/doc/mysql/en/char.html
Basically char is fixed length given by "char(x)" where x is the length of the string between 0 and 255. It uses x+2 bytes of storage if I remember correctly. If the string entered is shorter than x mysql adds spaces to ensure consistency in the number of bytes used.
varchar is variable length up to a maximum length of x "varchar(x)". Until MySQL 5 this was 0 to 255 too. In MySQL 5 it goes into 65K in length.
text is for longer extracts of text. It is all covered in the manual though

Posted: Mon Aug 29, 2005 6:15 am
by n00b Saibot
CHAR : 0-255 chars: takes as much space as defined.
VARCHAR : 0-255 chars : takes as much space as len of string
TEXT: 0-65535 chars : same as above
edit: I see that our old race continues here, d11wtq
difference of 1-2 minutes in posting together.
Posted: Mon Aug 29, 2005 6:35 am
by aaaphp000000
my host uses mysql 4.0 (or 4.1 - can not remember now).
the size or storage (in bytes) for
char(x) is : x+2
varchar(x) is : len+1 (len<=x<=255)
text is : len+2 (len<=65535)
are above right?
Posted: Mon Aug 29, 2005 6:50 am
by n00b Saibot
Yep!