What column type should be used to store serialized data in a mysql db?

前端 未结 8 1565
余生分开走
余生分开走 2020-12-08 01:45

What column type should be used to store serialized data in a mysql db? I know you can use varbinary, blob, text. What\'s considered the best and why?

Edit: I unders

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-08 02:24

    How much do you plan to store? Check out the specs for the string types at the MySQL docs and their sizes. The key here is that you don't care about indexing this column, but you also never want it to overflow and get truncated, since then you JSON is unreadable.

    • TINYTEXT L < 2^8
    • TEXT L < 2^16
    • MEDIUMTEXT L < 2^24
    • LONGTEXT L < 2^32

    Where L is the length in character

    Just plain text should be enough, but go bigger if you are storing more. Though, in that case, you might not want to be storing it in the db.

提交回复
热议问题