Correct mysql column type for holding strings of 100k in length?
I have a table in which I need to store some serialized json strings (mysql 5). I'm not sure what data type to use for the column which will do the storing. The strings will always be less than 100k.
There are a few different text types to choose from when looking at the docs, is there one that is most appropriate for a string of that length? It seems like MEDIUMTEXT would be开发者_开发百科 able to hold 100k strings?
http://dev.mysql.com/doc/refman/5.0/en/string-type-overview.html
MEDIUMTEXT column will be able to hold text of size 100K. I would suggest compressing the json data before storing it. That would reduce the storage size and would result in better db performance. If compressed a TEXT column should be able able to hold the data mostly.
MEDIUMTEXT will work fine. According to the MySQL docs, the size of text types is:
TINYBLOB, TINYTEXT: 28
BLOB, TEXT: 216
MEDIUMBLOB, MEDIUMTEXT: 224
LONGBLOB, LONGTEXT: 232
If you compress as @Damodharan suggests, be aware that compression and decompression take time. Disk space is cheap.
精彩评论