How to get size of BLOB in MySQL

Recently I wanted to get the size of the data stored in the BLOB field of a MySQL table. BLOB is a field which can be used to store variable amount of data. There is a simple MySQL String function, to find the size of BLOB data, OCTET_LENGTH. This function returns the length of BLOB in bytes. You can also use LENGTH function, because OCTET_LENGTH is synonym for LENGTH.

Sample usage:
Suppose in a table test_blob, there is a BLOB column (blob_content). We want to find the length of the BLOB field where id = 1.

SELECT OCTET_LENGTH(blob_content) FROM test_blob WHERE id = 1
I prefer to use OCTET_LENGTH, instead of LENGTH because the function name implies that I would get the result in terms of bytes and not characters.

Related posts:

  1. MySQL ordering results by specific field values
  2. What does int(11) means in MySQL?
  3. Sample MySQL table
  4. How to Find and Replace Data in MySQL

2 thoughts on “How to get size of BLOB in MySQL”

Leave a Reply