I have to store large amount of HTML data in a database .
我必须在数据库中存储大量的HTML数据。
I have Googled and found something about the blob
datatype, I checked it and it is working correctly.
我已经谷歌搜索并发现了一些关于blob数据类型的东西,我检查了它并且它正常工作。
I need to store the HTML pages in the tables and need to show them correctly as web pages on demand.
我需要将HTML页面存储在表格中,并且需要根据需要将它们正确地显示为网页。
So, which is better for storing large HTML pages, text
or blob
?
那么,哪个更适合存储大型HTML页面,文本或blob?
2 个解决方案
#1
10
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.
我使用blob它是一个varbinary并且不进行任何翻译。所以你的html将以与它进入的方式完全相同的方式出现。
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.
如果你想搜索和索引html TEXT可能是更好的选择。在这种情况下,请确保使用正确的字符集。我推荐UTF8。
#2
0
Seven years have passed since this question was asked. The database industry is converging on using UTF-8 for all text.
自问这个问题以来已过去七年了。数据库行业正在融合使用UTF-8来处理所有文本。
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.
如果您使用TEXT并将其设置为CHARACTER SET utf8mb4,并且您对所有其他文本字段(除了postal_code,country_code,hex和其他一些定义为ascii的除外)也一样,那么TEXT就有意义了。
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.
但是,还有另一个考虑因素。如果您的HTML是整个页面,那么将它放在文件而不是数据库表中是很有意义的。这样,它可以通过HTTP直接获取。类似的图像和BLOB导致的参数,其中...是.jpg文件的URL。
#1
10
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.
我使用blob它是一个varbinary并且不进行任何翻译。所以你的html将以与它进入的方式完全相同的方式出现。
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.
如果你想搜索和索引html TEXT可能是更好的选择。在这种情况下,请确保使用正确的字符集。我推荐UTF8。
#2
0
Seven years have passed since this question was asked. The database industry is converging on using UTF-8 for all text.
自问这个问题以来已过去七年了。数据库行业正在融合使用UTF-8来处理所有文本。
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.
如果您使用TEXT并将其设置为CHARACTER SET utf8mb4,并且您对所有其他文本字段(除了postal_code,country_code,hex和其他一些定义为ascii的除外)也一样,那么TEXT就有意义了。
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.
但是,还有另一个考虑因素。如果您的HTML是整个页面,那么将它放在文件而不是数据库表中是很有意义的。这样,它可以通过HTTP直接获取。类似的图像和BLOB导致的参数,其中...是.jpg文件的URL。