Storing HTML in MySQL: blob or text?

后端 未结 2 2028
野趣味
野趣味 2020-12-11 01:46

I have to store large amount of HTML data in a database .

I have Googled and found something about the blob datatype, I checked it and it is working cor

相关标签:
2条回答
  • 2020-12-11 02:36

    Seven years have passed since this question was asked. The database industry is converging on using UTF-8 for all text.

    If you use TEXT and make it CHARACTER SET utf8mb4, and you do likewise for all other text fields (except postal_code, country_code, hex, and a few other that are defined to be ascii), then TEXT makes sense.

    But, there is another consideration. If your HTML is an entire page, it makes good sense to put that in a file, not a database table. That way, it can be fetched directly by HTTP. Similarly images and BLOB lead to a argument for <img src=...> where ... is the url of a .jpg file.

    0 讨论(0)
  • 2020-12-11 02:40

    I'd use blob it's a varbinary and does not do any translation. So your html will come out exactly the same way that it went in.

    If you want to search and index that html TEXT may be a better choice. In that case make sure you use the proper charset.
    I'd recommend UTF8.

    0 讨论(0)
提交回复
热议问题