Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL TEXT vs BLOB vs CLOB

Tags:

mysql

What are the differences, advantages and disadvantages of these different data-types both from a performance standpoint as well as a usability standpoint?

like image 837
Jake Wilson Avatar asked Aug 15 '11 22:08

Jake Wilson


People also ask

What is the difference between TEXT and BLOB in MySQL?

What are the differences between the BLOB and TEXT datatypes in MySQL? BLOB stands for Binary Large Objects and as its name suggests, it can be used for storing binary data while TEXT is used for storing large number of strings.

Does MySQL support CLOB data type?

CLOB stands for Character Large Object. in general, an SQL Clob is a built-in datatype which is used to store large amount of textual data. Using this datatype, you can store data up to 2,147,483,647 characters. MYSQL database provides support Clob datatype TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT.


2 Answers

TEXT is a data-type for text based input. On the other hand, you have BLOB and CLOB which are more suitable for data storage (images, etc) due to their larger capacity limits (4GB for example).

As for the difference between BLOB and CLOB, I believe CLOB has character encoding associated with it, which implies it can be suited well for very large amounts of text.

BLOB and CLOB data can take a long time to retrieve, relative to how quick data from a TEXT field can be retrieved. So, use only what you need.

like image 154
Baseer Avatar answered Oct 16 '22 20:10

Baseer


It's worth to mention that CLOB / BLOB data types and their sizes are supported by MySQL 5.0+, so you can choose the proper data type for your need.

http://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html

Data Type   Date Type   Storage Required
(CLOB)      (BLOB)

TINYTEXT    TINYBLOB    L + 1 bytes, where L < 2**8  (255)
TEXT        BLOB        L + 2 bytes, where L < 2**16 (64 K)
MEDIUMTEXT  MEDIUMBLOB  L + 3 bytes, where L < 2**24 (16 MB)
LONGTEXT    LONGBLOB    L + 4 bytes, where L < 2**32 (4 GB)

where L stands for the byte length of a string
like image 28
Jonathan L Avatar answered Oct 16 '22 19:10

Jonathan L