MySQL
Database Size
Database Management
SQL Commands
Data Storage

How to check the size of a MySQL database

Codemia Knowledge Hub ·

Query information_schema.TABLES and add up data_length + index_length for the schema. That gives the database size in bytes, which you can divide down to megabytes. You can also read sizes in MySQL Workbench or check the data directory on disk.

Using an SQL query

Run this from the MySQL command line, MySQL Workbench or any other client:

sql
1SELECT table_schema AS 'Database', 
2SUM(data_length + index_length) / 1024 / 1024 AS 'Size (MB)' 
3FROM information_schema.TABLES 
4WHERE table_schema = 'your_database_name' 
5GROUP BY table_schema;

Replace 'your_database_name' with your database name. The query sums the data and index lengths stored in information_schema.TABLES and converts bytes to megabytes.

A database's total size includes all its tables and indexes. For a per-table or per-index breakdown, modify the query to return size information for each table or index.

Using MySQL Workbench

  1. Open MySQL Workbench and connect to your database server.
  2. Navigate to the "Management" section and select "Server Status."
  3. Scroll to the "Storage" section where you will see the total size of each database listed.

Checking the file system

If you have direct access to the server, check the database directories in the MySQL data directory. Each database is typically stored in its own directory there (/var/lib/mysql/ on Linux).

bash
du -sh /var/lib/mysql/*

This shows each database directory's size in human-readable form (for example MB or GB).

Running these queries or commands frequently, or on large databases, can affect performance. Consider running them during off-peak hours if needed.

Which method to use

MethodTool/ApproachComplexityBest Use Case
SQL QueryCommand Line/SQL InterfaceLowWhen you need quick programmatic access.
MySQL WorkbenchGUILowFor users who prefer a graphical interface.
File System CheckServer Access / Command LineMediumWhen having direct access to the server.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design