views:

752

answers:

2

Reading this question a doubt poped into my head:

  • char and varchar can store up to 255 chars
  • text can store up to 65k chars
  • char size in bytes is number of chars
  • varchar size in bytes is number of chars used + 1

So how much bytes does TEXT actually occupies? ~65kb or number of chars used + 1?

+3  A: 

TEXT is a variable length datatype, with a maximum of 65,000 characters.

http://simonwillison.net/2002/Aug/1/mysqlTextLimits/

LONGTEXT can be used for over 4 trillion characters.

To answer your question: it's a variable lenght, and it will only occupy the amount of characters you store.

Pindatjuh
Plus a little bit of overhead to indicate that length - and LONGTEXT has more overhead than TEXT has more overhead than VARCHAR.
Anon.
True: "LONG" in "LONGTEXT" actually indicates how much characters. A long value is 8 bytes, so the overhead is 8 bytes. Though it's insignificant, thus I didn't mention it.
Pindatjuh
Logically, TEXT is also stored as a BLOB
Evan Carroll
+1  A: 

TEXT occupies a number actual length of your data + 2 bytes.

Aleksandr