35

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?

2
  • 5
    stackoverflow.com/search?q=[mysql]+text+vs+varchar Commented Jan 18, 2010 at 3:57
  • 2
    varchar size in bytes is number of chars used + 1 This actually depends on the encoding used in the table. It could, for example, be ((# of chars) * 2) + 1 for 2-byte characters. Remember it's number of characters not number of bytes. Commented Jun 26, 2010 at 0:37

2 Answers 2

30

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Plus a little bit of overhead to indicate that length - and LONGTEXT has more overhead than TEXT has more overhead than VARCHAR.
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.
Logically, TEXT is also stored as a BLOB
9

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

1 Comment

Soooo if you're storing 256 or more characters, VARCHAR and TEXT take up the same amount of storage space?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.