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.
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.
A BLOB (binary large object) is a varying-length binary string that can be up to 2,147,483,647 characters long.
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.
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).
select sum(length(blob_column)) as total_size from your_table
You can use the MySQL function OCTET_LENGTH(your_column_name)
. See here for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With