Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating total data size of BLOB column in a table

Tags:

mysql

blob

I have a table with large amounts of BLOB data in a column. I am writing a utility to dump the data to file system. But before dumping, I need to check if necessary space is available on the disk to export all the blob fields throughout the table.

Please suggest an efficient approach to get size of all the blob fields in the table.

like image 935
jatinpreet Avatar asked May 18 '12 07:05

jatinpreet


People also ask

How do you measure the size of a BLOB?

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.

What is the size of BLOB in Oracle?

A BLOB (binary large object) is a varying-length binary string that can be up to 2,147,483,647 characters long.

What is the size of BLOB in MySQL?

BLOB: Can handle up to 65,535 bytes of data. MEDIUMBLOB: The maximum length supported is 16,777,215 bytes. LONGBLOB: Stores up to 4,294,967,295 bytes of data.

How much data can a BLOB store?

A BLOB can be 65535 bytes (64 KB) maximum. If you need more consider using: a MEDIUMBLOB for 16777215 bytes (16 MB) a LONGBLOB for 4294967295 bytes (4 GB).


2 Answers

select sum(length(blob_column)) as total_size  from your_table 
like image 44
juergen d Avatar answered Sep 29 '22 09:09

juergen d


You can use the MySQL function OCTET_LENGTH(your_column_name). See here for more details.

like image 92
Bud Damyanov Avatar answered Sep 29 '22 08:09

Bud Damyanov