MySQL: Check Database and Table Size

Check Using Query

This process will work in all cases, whether you are accessing your database through the command line or using any GUI tool (like MySQL Workbench or HeidiSQL).

Because the size-related information is already saved in a specific MySQL table. Check the following table:

Database Nameinformation_schema
Table NameTABLES

By checking the table named “TABLES” from the database “information_schema” you will find all the information related to the sizes of the tables. 

There are lots of information in that table. But I would like to point out a few important columns:

TABLE_SCHEMAName of the Database
TABLE_NAMEName of the Table
TABLE_ROWSNumber of rows in the table
DATA_LENGTHSize of total data for that table (in Byte)
INDEX_LENGTHSize of the total index for that table (in Byte)

You can check the data directly from the table. Just remember that the size/length is in Byte, so make sure to convert that to make it more understandable.

Or you can use the following queries to get the summary easily.

Check Table Size

If you want to get the size of the tables of a database, then use the following query:

(Make sure to use your database name in place of ‘your_db_name‘)

SELECT
  TABLE_SCHEMA AS "DB Name",
  TABLE_NAME AS "Table Name",
  TABLE_ROWS AS "Number of Rows",
  AVG_ROW_LENGTH AS "Avg Row Length",
  ROUND(
    DATA_LENGTH / POWER(1024, 2),
    2
  ) AS "Data Size (MB)",
  ROUND(
    INDEX_LENGTH / POWER(1024, 2),
    2
  ) AS "Index Size (MB)",
  ROUND(
    (DATA_LENGTH + INDEX_LENGTH) / POWER(1024, 2),
    2
  ) AS "Total Table Data Size (MB)"
FROM
  information_schema.TABLES
WHERE
  TABLE_SCHEMA = "your_db_name"
ORDER BY
  `Total Table Data Size (MB)` DESC;

Running this query will show the result like below:

DB NameTable NameNumber of RowsAvg Row LengthData Size (MB)Index Size (MB)Total Table
Data Size (MB)
your_db_nametimeline_data30107517056161641240228566
your_db_namestaff_details277782126717975384.977181.97
your_db_namelocation_data508692993452481.02933.02
your_db_namechain_data232260568150.69398.03548.72
your_db_nameemployee_data281895663170.72226.06396.78
your_db_namestaffs21955514129.5658.6488.2
your_db_namebuild_details107190636.529.0315.55

Check Database Size

If you want to get the total sizes of each database in the server, use the following query:

SELECT
  TABLE_SCHEMA AS "DB Name",
  ROUND(
    SUM(DATA_LENGTH) / POWER(1024, 2),
    2
  ) AS "Data Size (MB)",
  ROUND(
    SUM(INDEX_LENGTH) / POWER(1024, 2),
    2
  ) AS "Index Size (MB)",
  ROUND(
    SUM(DATA_LENGTH + INDEX_LENGTH) / POWER(1024, 2),
    2
  ) AS "Total Database Size (MB)"
FROM
  information_schema.TABLES
GROUP BY
  TABLE_SCHEMA
ORDER BY
  `Total Database Size (MB)` DESC;

Running this query will show the result like below:

DB NameData Size (MB)Index Size (MB)Total Database Size (MB)
testdb18874.5619066.2737940.83
testdb_demo142.33117.33259.66
testdb_pc6.593.4210.02
mysql3.250.303.55
testdb_test0.340.620.97
testdb_new0.330.160.48
sys0.020.000.02
information_schema0.000.000.00
performance_schema0.000.000.00

Check using GUI

MySQL WorkBench

Right-click on the database name and select the option “Schema Inspector” (or you can click on the info icon on the right side of database name).

In the new view check the following 2 tabs:

1. Info – Gives a summary of the database.

2. Tables – Gives all the informion about the tables (including size)

HeidiSQL

This tool already shows the size information for database and tables beside the database/table name. So no additional steps required, if you are using HeidiSQL.

phpMyAdmin

phpMyAdmin shows the table size information on the structure view.

Leave a Comment


The reCAPTCHA verification period has expired. Please reload the page.