How to Check MySQL Database and Table Size
Find large databases and tables using SQL in seconds.
Before you start
Check database size
SELECT count(*) NUM_OF_TABLE,
table_schema,
concat(round(sum(table_rows)/1000000,2),'M') rows,
concat(round(sum(data_length)/(1024*1024*1024),2),'G') DATA,
concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(sum(index_length)/sum(data_length),2) idxfrac
FROM information_schema.TABLES
GROUP BY table_schema
ORDER BY sum(data_length+index_length) DESC
LIMIT 10;
DATA = data size, idx = index size, total_size = total usage.
Check table size
SELECT
table_name,
table_rows,
round(data_length/(1024*1024),2) AS DATA_SIZE_MB,
round(index_length/(1024*1024),2) AS INDEX_SIZE_MB
FROM information_schema.TABLES
WHERE table_schema = 'your_database_name'
ORDER BY data_length DESC;
Replace 'your_database_name' with your actual database name.
Common issues
In InnoDB, row count is approximate.
You need access to information_schema.
Make sure you replace the schema name correctly.
About this guide
This guide shows how to check MySQL database size and table size using information_schema. It is useful when you want to identify large databases or tables.
How to follow this guide
- Run a query to check database size.
- Run a query to check table size.
- Analyze which database or table is consuming the most space.
Why use this method?
Knowing database and table size helps you manage storage, optimize performance, and identify unnecessary data.
Frequently Asked Questions
Is table_rows accurate?
For InnoDB tables, table_rows is an estimate, not exact.
What is information_schema?
It is a system database that stores metadata about all tables and schemas.
Why is index size large?
Large indexes may indicate heavy indexing or inefficient schema design.
Do I need special permissions?
You need permission to read information_schema tables.