Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing HTML in MySQL: blob or text?

Tags:

mysql

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 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?

like image 502
Red Avatar asked Oct 02 '11 13:10

Red


People also ask

What is difference between BLOB and TEXT in MySQL?

BLOB values are treated as binary strings (byte strings). They have the binary character set and collation, and comparison and sorting are based on the numeric values of the bytes in column values. TEXT values are treated as nonbinary strings (character strings).

Is it good to store HTML in database?

Storing HTML code is fine. But if it is not from trusted source, you need to check it and allow a secure subset of markup only. HTML Tidy library will help you with that. Also, you need to count with a future change in website design, so do not use too much markup, only basic tags.

Can we store BLOB in MySQL?

In MySQL, we can use BLOB datatype to store the files. A BLOB is a binary large object that can hold a variable amount of data. We can represent the files in binary format and then store them in our database. The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB.

Why BLOB is used in MySQL?

BLOB, which stands for a Binary Large Object, is a MySQL data type that can store images, PDF files, multimedia, and other types of binary data.


1 Answers

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.

like image 116
Johan Avatar answered Oct 13 '22 22:10

Johan