Get MySQL Table Size

MySQL table size

MySQL Table Size

What to do if you need to know some MySQL database table real size? Thanks to MySQL, it is not very complex task. There is no need to know the table row length and multiply it on quant of rows in that table. Just remember about MySQL system database called information_schema. It has right information for those who want to get DB table real size. Let’s look into the information_schema.tables table. We will use next fields from it:
TABLE_SCHEME (database name),
TABLE_NAME (it is self-explaining),
TABLE_ROWS (quant of rows in the table),
DATA_LENGTH (table data length in bytes),
INDEX_LENGTH (table indexes length in bytes)
Let’s suppose that our database is named as wpmu, take your favorite MySQL client tool (I use SQLyog Community Edition – MySQL GUI product) and try this query:

SELECT TABLE_NAME AS "Table Name", 
      table_rows AS "Quant of Rows", 
      ROUND((data_length + index_length)/1024,2) AS "Total Size Kb"
  FROM information_schema.tables
  WHERE information_schema.tables.table_schema='wpmu'

The result can be looked as:

MySQL tables size query result

MySQL tables size query result

Tags: ,