10

How to get each row size of a table in MySQL i.e total size of the space taken by a row. Assume a table has BLOB column. Not all row will be of same size. I want to list out all BLOB column i.e text column which is of greater size. Similarly collective size of a single row.

Is it possible to retrieve each row size of a table in a single query?

5
  • 1
    What do you mean by "row size"? The actually used filesystem storage? The number of columns? The length of all strings appended?
    – feeela
    Jun 23, 2014 at 12:08
  • if It is no of characters, then concat all column and have length function on final result, this will return size of each row. Jun 23, 2014 at 12:09
  • @Khatir what you mean by row size can you explain more??
    – Sadikhasan
    Jun 23, 2014 at 12:11
  • Voted to close the question since it's unclear what's being asked here.
    – Rahul
    Jun 23, 2014 at 12:23
  • This might help - stackoverflow.com/a/30644836/341117 Sep 28, 2020 at 9:35

1 Answer 1

0

Not sure how to get the each row size of a table..However able to find the query for table, database sizes. It seems it is not possible.

List Table Sizes From a Single Database

Assume the database name as "example"

SELECT
  TABLE_NAME AS `Table`,
  ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
FROM
  information_schema.TABLES
WHERE
  TABLE_SCHEMA = "example"
ORDER BY
  (DATA_LENGTH + INDEX_LENGTH)
DESC;

Entire databases size

SELECT table_schema "Data Base Name", sum( data_length + index_length) / 1024 / 1024
"Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema ;

SELECT sum(ROUND(((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024),2)) "Size in MB"
FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = "your_db_name";

SELECT table_schema as 'Database Name', 
        sum( data_length + index_length ) as 'Size in Bytes',       
        round((sum(data_length + index_length) / 1024 / 1024), 4) as 'Size in MB'
 FROM     information_schema.TABLES
 GROUP BY table_schema;
1
  • Good and simple stuff. Thanks! Apr 5, 2021 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.