• /
  • /

How to Check MySQL Table and Database Size

Written By ROMAN AGABEKOV | APR 22, 2024

Last update | SEP 10, 2026

To check MySQL table or database size, query INFORMATION_SCHEMA.TABLES and add DATA_LENGTH + INDEX_LENGTH. Filter by database or table name, or sort the results to find the largest tables. For InnoDB, these are approximate allocated index sizes, not an exact measurement of files on disk.

The SQL examples below cover one database, every database, individual tables, and index storage. They do not require MySQL Workbench (how to optimize queries faster than in MySQL Workbench) or phpMyAdmin.

Check MySQL Data Directory Disk Usage

Before digging into specific databases and table sizes, it's helpful to know the overall disk usage of your MySQL data directory. This information typically requires server access and cannot be obtained via SQL commands. You would need to use system commands like du in Linux:
Linux command to reveal how much disk space the MySQL data directory
du -sh /var/lib/mysql
This command reveals how much disk space the MySQL data directory, usually found at /var/lib/mysql, is taking up. This information is key for effectively managing server resources and planning any necessary expansions or optimizations.

How to Check the Size of a Specific Database

Understanding the size of a specific MySQL database is important for various reasons. You might need to track its growth, prepare for backups, or make sure it stays within your environment's storage limits. This information becomes particularly valuable when you're planning for future capacity needs or migrating databases to a new server.

To accurately determine the size of a particular MySQL database, use the following SQL query:
SQL command to determine the size of a particular MySQL database
SELECT table_schema AS "Database",
       ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"
FROM information_schema.tables
WHERE table_schema = 'your_database_name'
GROUP BY table_schema;
Replace 'your_database_name' with your database name. Dividing by 1024 twice reports mebibytes (MiB); the existing SQL examples label this column MB.

For InnoDB, DATA_LENGTH estimates the space allocated to the clustered index, which contains the row data; INDEX_LENGTH estimates the space allocated to secondary indexes. Their sum is useful for comparing table sizes, but is not an exact filesystem total. Deleting rows does not guarantee that the table file shrinks.

Index storage size alone does not tell you how much memory the workload needs. See our guide on MySQL index length and performance optimization.

Check MySQL Database Size all at once

Whether it's to ensure that none of the databases grow unexpectedly large, manage storage capacity, or perform regular health checks – knowing the size of each database can provide valuable insights into your server's overall utilization.

To retrieve the size of each database on your MySQL server, use the following SQL query:
SQL command to retrieve the size of each database on your MySQL server
SELECT table_schema AS "Database",
       ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"
FROM information_schema.tables
GROUP BY table_schema;
This SQL command collects data from the information_schema.tables table, which contains metadata about all tables in all databases. The table_schema column represents the database name, while data_length and index_length represent the size of the table data and indexes, respectively.

It sums the data_length and index_length for all tables in each database, providing a comprehensive total for each. The sum is then converted from bytes to megabytes (MB) for easier interpretation.

Check MySQL Table Size

Large tables can slow down query performance. Checking in on your table sizes helps you identify candidates for optimization, such as indexing and partitioning. These tables might also need more time for maintenance tasks like backups and restores. Sizing information allows you to plan for these operations more effectively.

To check the size of a specific table within a database, you can run:
SQL command to check the size of a specific table within a database
SELECT TABLE_NAME AS "Table",
              ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.tables
WHERE table_schema = 'your_database_name'
  AND TABLE_NAME = 'your_table_name';
Replace 'your_database_name' and 'your_table_name' with your specific database and table name. The query calculates the total size of the table by summing the data_length (the space used by the table's data) and index_length (the space used by the table's indexes). The result is then converted from bytes to megabytes for readability.

How to check row count and free space per table

You can extend the previous query to show estimated row counts and the DATA_FREE value reported for each table's tablespace.
SQL command to check the size of a specific table within a database
SELECT 
  TABLE_NAME,
  TABLE_ROWS,
  ROUND(DATA_LENGTH / 1024 / 1024, 2) AS data_mb,
  ROUND(INDEX_LENGTH / 1024 / 1024, 2) AS index_mb,
  ROUND(DATA_FREE / 1024 / 1024, 2) AS free_mb
FROM information_schema.TABLES
WHERE table_schema = 'your_database_name'
ORDER BY data_mb + index_mb DESC;
For InnoDB, TABLE_ROWS is an estimate. DATA_FREE describes allocated but unused space in the table's tablespace. For tables in a shared tablespace, this can be the shared free space, not space belonging only to that table. Do not add these values across shared-tablespace tables or treat them as bytes that a rebuild will necessarily return to the operating system.

How to List All Table Sizes from All Databases

In MySQL, it's often necessary to get a comprehensive view of the sizes of all tables across all databases, particularly for system-wide performance analysis, storage optimization, and monitoring general data growth. This kind of overview can help you quickly identify which tables are consuming the most storage space and may require intervention or reconfiguration.

To list the sizes of all tables across all databases, you can use the following SQL query:
SQL command to list the sizes of all tables across all databases
SELECT table_schema AS "Database",
       TABLE_NAME AS "Table",
                     ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.tables
ORDER BY data_length + index_length DESC;
The query selects the table_schema (database name) and table_name, along with the sum of data_length (actual data storage) and index_length (index storage). The results are ordered by the combined size of data and index lengths in descending order, showing the largest tables first. This prioritization helps you easily spot the biggest space consumers.

Calculate Index Storage Space

Looking to view or list your existing indexes?
If you want to see which columns are indexed rather than estimating index storage, read our complete guide on how to show and inspect MySQL indexes.
Checking index storage helps you understand how much space indexes occupy as a table changes. Storage size alone does not show whether an index improves a particular query.
To estimate the space allocated to an InnoDB table's secondary indexes, use:
SELECT TABLE_NAME AS "Table",
     ROUND((index_length / 1024 / 1024), 2) AS "Index Size (MB)"
FROM information_schema.tables
WHERE table_schema = 'your_database_name'
  AND TABLE_NAME = 'your_table_name';
Replace 'your_database_name' and 'your_table_name' with your specific database and table name.
For InnoDB, this estimates secondary-index allocation, not the clustered index or a separate index file's size.

How storage engines affect reported sizes

The meaning of these columns depends on the storage engine. For InnoDB, the values estimate allocated clustered and secondary index space; they are not exact file sizes.

A table may use its own file-per-table tablespace or share a tablespace. The current innodb_file_per_table setting does not by itself prove where an existing table is stored. SQL size estimates and filesystem disk usage can differ in either case.

Performance and troubleshooting tips

Filter size queries by database when you only need one database, and compare measurements taken in the same way over time.

A large table or a high DATA_FREE value is not, by itself, a reason to partition, rebuild, or run OPTIMIZE TABLE. Those operations require a separate assessment of the storage layout, workload, available space, and maintenance risk.

Tired of running manual commands? Automate your MySQL database health check and track performance instantly with Releem MySQL Monitoring.

Learn more about MySQL index performance, including complex JSON indexes.
FAQ:
How to Check MySQL Table and Database Size
What do data_length and index_length mean?
In information_schema.tables:
  • For InnoDB, DATA_LENGTH estimates space allocated to the clustered index, which contains the rows.
  • For InnoDB, INDEX_LENGTH estimates space allocated to secondary indexes.
Their sum is an approximate allocated index size for InnoDB, not an exact filesystem footprint.

Why do we divide by 1024 / 1024 in these queries?
MySQL reports these lengths in bytes. Dividing by 1024 twice converts bytes to mebibytes (MiB):
  • 1 KiB = 1024 bytes
  • 1 MiB = 1024 KiB
The existing examples label MiB as MB. ROUND(..., 2) limits the result to two decimal places for readability.

Can I display larger sizes in GiB?
Yes. Divide by 1024 three times to report gibibytes (GiB), and adjust the label:
---
ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 2) AS "Size (GiB)"
---
This works in all the size queries shown above.

Why use SQL queries instead of only du on the filesystem?
  1. du reports filesystem usage for the paths you measure; SQL provides table-level size estimates, including when tables share a tablespace.
  2. information_schema.tables lets you:
  • Break down usage per database.
  • Drill down per table.
  • Separate data vs. index usage.
  • Sort and filter to find the largest consumers.
Both approaches are complementary: du for overall footprint, SQL for fine‑grained analysis.

Article by

  • Founder & CEO
    Roman Agabekov has 17 years of experience managing and optimizing MySQL and MariaDB in high-load environments. He founded Releem to automate routine database management tasks like performance monitoring, tuning, and query optimization. His articles share practical insights to help others maintain and improve their databases.