Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the each row size of a table in mysql?

Tags:

mysql

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?

like image 984
Kathir Avatar asked Jun 23 '14 12:06

Kathir


People also ask

How do you determine row size?

For every row of every table, there is a 24-byte fixed overhead of the rowid, createxid, and deletexid. If you have any nullable columns, a null vector is required and it is N/8 bytes where N is the number of columns in the record. The system rounds up the size of this header to a multiple of 4 bytes.

What is row size in MySQL?

The internal representation of a MySQL table has a maximum row size limit of 65,535 bytes, even if the storage engine is capable of supporting larger rows. BLOB and TEXT columns only contribute 9 to 12 bytes toward the row size limit because their contents are stored separately from the rest of the row.

How do I find the size of a table in database?

This can be accomplished easily with the following query: SELECT TABLE_SCHEMA AS `Database`, TABLE_NAME AS `Table`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)` FROM information_schema.


1 Answers

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;
like image 198
Kathir Avatar answered Sep 19 '22 10:09

Kathir