Databases 2 min read

How to Quickly Check MySQL Database, Table, and Index Size with SQL

This guide shows how to use MySQL's information_schema tables to retrieve the total size of a database, individual table sizes, index sizes, and detailed per‑table statistics such as row count and combined data and index space, using concise SELECT statements.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
How to Quickly Check MySQL Database, Table, and Index Size with SQL

To view the total space occupied by a MySQL database, run:

SELECT CONCAT(ROUND((SUM(DATA_LENGTH)+SUM(INDEX_LENGTH))/(1024*1024),2),'M') AS 'Database Size' FROM information_schema.TABLES WHERE TABLE_SCHEMA='your_database_name';

To view the total space used by all tables in a specific database, run:

SELECT CONCAT(ROUND(SUM(DATA_LENGTH)/(1024*1024),2),' MB') AS 'Total Table Size' FROM information_schema.TABLES WHERE TABLE_SCHEMA LIKE 'your_database_name';

To view the total space used by all indexes in a specific database, run:

SELECT CONCAT(ROUND(SUM(INDEX_LENGTH)/(1024*1024),2),' MB') AS 'Total Index Size' FROM information_schema.TABLES WHERE TABLE_SCHEMA LIKE 'your_database_name';

For detailed per‑table information—including table name, row count, data size, index size, and total size—run:

SELECT CONCAT(TABLE_SCHEMA,'.',TABLE_NAME) AS 'Table Name',
       TABLE_ROWS AS 'Number of Rows',
       CONCAT(ROUND(DATA_LENGTH/(1024*1024),3),'M') AS 'Data Size',
       CONCAT(ROUND(INDEX_LENGTH/(1024*1024),3),'M') AS 'Index Size',
       CONCAT(ROUND((DATA_LENGTH+INDEX_LENGTH)/(1024*1024),2),'M') AS 'Total'
FROM information_schema.TABLES
WHERE TABLE_SCHEMA LIKE 'your_database_name';
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performanceSQLmysqlInformation Schemadatabase size
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.