Take the 2-minute tour ×

I am trying to save some xml into my mysql-database. But these chunks of xml can varry from 1000 to 1000000 characters. How can i save this into my database without reserving 100kb for each string, even if it is only 1kb long?


I have checked http://dev.mysql.com/doc/refman/5.1/en/storage-requirements.html They say, Text is stored in blocks of 2000 characters. Interesting is, that changing MEDIUMTEXT to LONGTEXT changes 22kb to 100kb. The textsize was the same, so it should remain on about 4000b (4kb)

Do you have any idea why this happens and how to prevent it?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

MySQL's variable-length string types allocate only the space required for store the data (together with its length). In your case, you will need the MEDIUMTEXT type to be able to store up to 1000000 characters.

share|improve this answer
Why not varchar? –  Jan Dvorak Jan 10 '13 at 12:06
@JanDvorak: VARCHAR can only store up to 16KiB, whereas 1000000 characters will require 1MiB even in a single-byte encoding. –  eggyal Jan 10 '13 at 12:07
I have tested it. I set MEDIUMTEXT and a text with 3k characters takes 22kb storage in the db... When i change the datatype to TEXT, its significantly decreases in size without cutofs. –  Kostronor Jan 10 '13 at 12:28

Your Answer


