Databases 2 min read

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.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
How to Check MySQL Database and Table Size Using information_schema

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';
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.

queryInformation Schematablesdatabase-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.