How to Check MySQL Database and Table Size Using information_schema
This guide explains how MySQL's information_schema.TABLES stores metadata such as database name, table name, engine, row count, data size, and index size, and provides SQL queries to retrieve the total space used by a specific database or table.
MySQL stores metadata about databases and tables in the information_schema database, specifically in the TABLES table.
The most relevant columns are:
TABLE_SCHEMA – database name
TABLE_NAME – table name
ENGINE – storage engine used
TABLE_ROWS – number of rows
DATA_LENGTH – size of the data
INDEX_LENGTH – size of the indexes
To query the total space used by a specific database:
SELECT CONCAT(ROUND(SUM(DATA_LENGTH/1024/1024),2),'MB') AS data FROM TABLES WHERE TABLE_SCHEMA='your_database_name';To query the space used by a particular table within that database:
SELECT CONCAT(ROUND(SUM(DATA_LENGTH/1024/1024),2),'MB') AS data FROM TABLES WHERE TABLE_SCHEMA='your_database_name' AND TABLE_NAME='your_table_name';Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
