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.
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.
2 thoughts on “How to get size of BLOB in MySQL”
Thanks, this solved my problem. Maybe you should remove the s from the code^^
In MySQL OCTET_LENGTH() is synonym of LENGTH()
So, you can use them both interchangeably.