What is the difference between BLOB and TEXT data types in MySQL?

WBOY
Release: 2023-09-07 09:49:01
forward
755 people have browsed it

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.

MySQL 中的 BLOB 和 TEXT 数据类型有什么区别?

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.

Create a table of TEXT data type

mysql> create table TextTableDemo -> ( -> Address TEXT -> ); Query OK, 0 rows affected (0.58 sec)
Copy after login

Describe the table with the DESC command.

mysql> DESC TextTableDemo;
Copy after login

The following is the output.

+---------+------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+------+------+-----+---------+-------+ | Address | TEXT | YES | | NULL | | +---------+------+------+-----+---------+-------+ 1 row in set (0.08 sec)
Copy after login

In the above output, "Type" represents the data type, which is TEXT.

Create a BLOB type table

mysql> create table BlobTableDemo -> ( -> Images BLOB -> ); Query OK, 0 rows affected (0.51 sec)
Copy after login

Let us get the description of the table with the help of DESC command.

mysql> desc BlobTableDemo;
Copy after login

The following is the output.

+--------+------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+------+------+-----+---------+-------+ | Images | BLOB | YES | | NULL | | +--------+------+------+-----+---------+-------+ 1 row in set (0.04 sec)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!