MySQL - TEXT vs CHAR and VARCHAR

Alix Axel picture Alix Axel · Jan 18, 2010 · Viewed 40.1k times · Source

Reading this question, a doubt popped 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 occupy? ~65KB or number of chars used + 1?

Answer

Pindatjuh picture Pindatjuh · Jan 18, 2010

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

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.