BLOB stands for Binary Large Objects. As the name suggests, it can be used to store binary data, while TEXT is used to store large amounts of strings. BLOB can be used to store binary data, which means we can also store pictures, videos, sounds, and programs.
For example, the image below can be stored as a BLOB because the image has binary data.
BLOB values behave like byte strings, and BLOBs have no character set. Therefore, comparison and sorting depend entirely on the numerical value of bytes.
TEXT values behave like non-binary strings or strings. TEXT has a character set, and comparison/sorting depends entirely on the collection of character sets.
mysql> create table TextTableDemo -> ( -> Address TEXT -> ); Query OK, 0 rows affected (0.58 sec)
Describe the table with the DESC command.
mysql> DESC TextTableDemo;
The following is the output.
+---------+------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+------+------+-----+---------+-------+ | Address | TEXT | YES | | NULL | | +---------+------+------+-----+---------+-------+ 1 row in set (0.08 sec)
In the above output, "Type" represents the data type, which is TEXT.
mysql> create table BlobTableDemo -> ( -> Images BLOB -> ); Query OK, 0 rows affected (0.51 sec)
Let us get the description of the table with the help of DESC command.
mysql> desc BlobTableDemo;
The following is the output.
+--------+------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+------+------+-----+---------+-------+ | Images | BLOB | YES | | NULL | | +--------+------+------+-----+---------+-------+ 1 row in set (0.04 sec)
In the example output, "Type" indicates that the data type is BLOB.
The above is the detailed content of What is the difference between BLOB and TEXT data types in MySQL?. For more information, please follow other related articles on the PHP Chinese website!