MySQL
BLOB
TEXT
Datatypes
Database

What are the differences between the BLOB and TEXT datatypes in MySQL?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

BLOB and TEXT look similar because both store variable-length large values and both come in TINY, regular, MEDIUM, and LONG sizes. The real difference is not capacity but interpretation: BLOB stores binary bytes, while TEXT stores character data with character-set and collation rules.

The Core Distinction

Use BLOB when the database should treat the value as raw bytes. Use TEXT when the value is textual content that should participate in character-aware comparison and collation.

That means:

  • 'BLOB has binary semantics'
  • 'TEXT has string semantics'

This affects sorting, comparison, indexing behavior, and how the server interprets the contents.

Size Families

The size families mirror each other:

  • 'TINYBLOB and TINYTEXT'
  • 'BLOB and TEXT'
  • 'MEDIUMBLOB and MEDIUMTEXT'
  • 'LONGBLOB and LONGTEXT'

The paired types have the same storage-size limits. The practical difference is still binary versus character treatment.

Character Set and Collation

TEXT columns use a character set and collation, so MySQL understands them as text:

sql
1CREATE TABLE articles (
2    id BIGINT PRIMARY KEY,
3    body TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
4);

BLOB columns do not have text collation semantics:

sql
1CREATE TABLE files (
2    id BIGINT PRIMARY KEY,
3    payload BLOB
4);

That makes BLOB appropriate for data such as images, compressed payloads, encrypted bytes, or protocol buffers.

Comparison Behavior

A TEXT comparison is affected by collation rules. For example, case-insensitive collations may treat some values as equal for comparison purposes.

A BLOB comparison is byte-oriented. MySQL does not interpret the bytes as text using a character set.

That distinction matters when you sort or compare:

  • user comments, article bodies, and JSON text usually belong in TEXT
  • image bytes, ZIP data, or serialized binary payloads belong in BLOB

Indexing and Query Design

Large object columns often need prefix indexes rather than full indexing, depending on the use case:

sql
1CREATE TABLE notes (
2    id BIGINT PRIMARY KEY,
3    content TEXT,
4    INDEX idx_content_prefix (content(100))
5);

The right index strategy depends on query patterns. But conceptually, if you are searching natural language or doing character-based comparisons, TEXT is the correct family. If you are storing opaque bytes, BLOB is the correct family.

Application-Level Consequences

Choosing the wrong type can cause friction:

  • storing binary data in TEXT risks encoding confusion
  • storing human-readable text in BLOB makes collation-aware search and comparison harder

The database type should reflect how the application intends to use the value, not just how large it is.

Example Rule of Thumb

Use TEXT for:

  • article bodies
  • markdown
  • logs stored as readable strings
  • long descriptions

Use BLOB for:

  • images
  • PDFs
  • compressed archives
  • encrypted or non-text payloads

That rule is not arbitrary. It aligns with how MySQL treats the data internally and during comparisons.

Common Pitfalls

The biggest mistake is choosing between BLOB and TEXT based only on size. Their size tiers match, so that is not the deciding factor.

Another mistake is storing encoded binary data as text just because it "looks readable" after base64 conversion. That increases size and changes semantics unnecessarily.

A third issue is ignoring collation behavior. If the application needs case-insensitive or locale-aware text comparisons, TEXT is the right family and BLOB is not.

Summary

  • 'BLOB stores binary bytes; TEXT stores character data.'
  • Their size families correspond, so size alone is not the real difference.
  • 'TEXT participates in character-set and collation rules.'
  • 'BLOB is appropriate for opaque binary payloads.'
  • Choose the type based on how the data will be compared, indexed, and used by the application.

Course illustration
Course illustration

All Rights Reserved.