开发者

Storing HTML in MySQL: blob or text?

开发者 https://www.devze.com 2023-04-10 16:50 出处:网络
I have to store large amount of HTML data in a database . I have Googled a开发者_JAVA百科nd found something about the blob datatype, I checked it and it is working correctly.

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

I have Googled a开发者_JAVA百科nd found something about the blob datatype, I checked it and it is working correctly.

I need to store the HTML pages in the tables and need to show them correctly as web pages on demand.

So, which is better for storing large HTML pages, text or blob?


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号