Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What structure type do I use for HTML content (MySQL)

Tags:

html

sql

mysql

I want to put a minified string of HTML into a database row - bare in mind it could be pretty large string, what kind of structure type do I use out of the following:

http://d.pr/2URu

I've tried LONGTEXT but that doesn't seem to work when I try to insert.

like image 704
daryl Avatar asked Oct 20 '11 09:10

daryl


People also ask

Which data type is used in MySQL to store text?

The four BLOB types are TINYBLOB , BLOB , MEDIUMBLOB , and LONGBLOB . These differ only in the maximum length of the values they can hold. The four TEXT types are TINYTEXT , TEXT , MEDIUMTEXT , and LONGTEXT . These correspond to the four BLOB types and have the same maximum lengths and storage requirements.

Which data types are supported by MySQL?

MySQL supports SQL data types in several categories: numeric types, date and time types, string (character and byte) types, spatial types, and the JSON data type.

What is the difference between varchar and text in MySQL?

Some Differences Between VARCHAR and TEXTThe VAR in VARCHAR means that you can set the max size to anything between 1 and 65,535. TEXT fields have a fixed max size of 65,535 characters. A VARCHAR can be part of an index whereas a TEXT field requires you to specify a prefix length, which can be part of an index.

Does MySQL support Boolean data type?

MySQL does not have a boolean (or bool) data type. Instead, it converts boolean values into integer data types (TINYINT). When you create a table with a boolean data type, MySQL outputs data as 0, if false, and 1, if true.


2 Answers

LONGTEXT is probably excessive -- it allows data sizes up to 4GB.

MEDIUMTEXT allows 16MB.

TEXT allows 64KB.

TINYTEXT allows only 255 characters.

Very few HTML documents are going to be 64KB in size, so a TEXT ought to be suitable for you. If you really want to be safe, go for a MEDIUMTEXT.

Reference: http://dev.mysql.com/doc/refman/5.0/en/string-type-overview.html

like image 66
Spudley Avatar answered Oct 21 '22 16:10

Spudley


I would use TEXT. What are the options you were thinking about?

like image 33
PiTheNumber Avatar answered Oct 21 '22 16:10

PiTheNumber