views:

44

answers:

2

What is the difference between char and tinytext in MySQL?

+3  A: 

char[] is fixed and tinytext is variable up to 255 characters.

Otávio Décio
What do you mean by fixed? Which one requires more space in the db?
ilhan
@ilhan: "fixed" means that CHAR(10) will allocate 10 characters, regardless how long the actual text is. IE: In a CHAR(10) column, adding "a" will result in the value being stored as "a_________" (had to use underscores cuz comments eat the whitespace...).
OMG Ponies
+1  A: 

One difference is the way MySQL stores the data.

For a TEXT field, MySQL will allocate 256 bytes in the original table and then store the remainder of the data in 2,000 byte chunks in a separate, hidden table.

For a CHAR field, you must declare the fixed size when creating the table (up to 256) and MySQL will always use this amount of space to store each record (padding with spaces as needed).

Ben Hoffstein