MySQL
BLOB column
data length
database
SQL storage limits

What is the maximum length of data I can put in a BLOB column in MySQL?

Master System Design with Codemia

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

In MySQL, a BLOB (Binary Large Object) is a data type designed to store binary data, including images, multimedia files, and other large objects. BLOBs are an essential feature of databases in scenarios where storing raw binary data within the confines of a conventional data type would be impractical. When working with BLOBs, understanding the limits of how much data can be stored is crucial.

Understanding BLOB Types in MySQL

MySQL offers four types of BLOBs, each varying in storage capacity:

  1. TINYBLOB: Generally used for small binary data objects.
  2. BLOB: Suitable for holding medium-sized data.
  3. MEDIUMBLOB: Handles larger blobs, up to 16MB.
  4. LONGBLOB: Designed for very large binary objects.

Storage Capacity of BLOB Types

Here is a summary of the maximum data size each BLOB type can hold:

BLOB TypeMaximum Storage Capacity
TINYBLOB255 bytes
BLOB65,535 bytes (64 KiB)
MEDIUMBLOB16,777,215 bytes (16 MiB)
LONGBLOB4,294,967,295 bytes (4 GiB)

Explanation of BLOB Limits

  • TINYBLOB: The smallest of the BLOB types, TINYBLOB, is typically used for short binary data fields, such as icons or small audio clips.
  • BLOB: A plain BLOB can hold around 64 KiB, making it useful for slightly larger objects, like small images.
  • MEDIUMBLOB: With its ability to store up to 16 MiB, the MEDIUMBLOB is appropriate for full images or medium-sized files.
  • LONGBLOB: A LONGBLOB can manage extremely large data sizes up to approximately 4 GiB, catering to the storage needs of large videos or datasets.

Technical Considerations

Internal Storage

Internally, MySQL BLOB types are stored as binary strings with varying lengths depending on the type. The storage size mentioned does not include any possible overhead associated with headers or metadata MySQL might maintain alongside the BLOB data.

Memory Usage and Performance

When using BLOBs, it's important to keep in mind the implications of handling large data volumes. If your application retrieves substantial BLOBs frequently, it may impose a significant strain on memory usage and network throughput, impacting application and database performance. Optimizing BLOB handling involves strategies such as:

  • Streaming Data: Instead of loading entire BLOBs into memory, consider streaming the data directly to where it’s needed.
  • Normalization: Store metadata differently when possible, and use the BLOB column strictly for the binary data.
  • Indexes: Avoid over-indexing BLOB data, as it can lead to performance issues.

Example of Usage

Here's an example to demonstrate the creation and usage of a BLOB column:


Course illustration
Course illustration

All Rights Reserved.