Skip to content
DBAExperts
MySQL Operations

How to monitor database size and growth in MySQL

Knowing how much space your data takes and how fast it grows is fundamental for planning disk and anticipating problems. MySQL exposes this information in information_schema.tables, with estimates of data and index space per table.

  1. 1

    Measure the total size per database

    Sum the data and indexes across all tables and convert it to megabytes. It gives you the big picture at a glance.

    SELECT table_schema AS base,
           ROUND(SUM(data_length + index_length)/1024/1024, 1) AS tamano_mb
    FROM information_schema.tables
    GROUP BY table_schema
    ORDER BY tamano_mb DESC;
  2. 2

    Find the largest tables

    Separate data from indexes: sometimes the indexes weigh more than the data, and that is something to look into.

    SELECT table_schema, table_name,
           ROUND(data_length/1024/1024, 1) AS datos_mb,
           ROUND(index_length/1024/1024, 1) AS indices_mb,
           table_rows AS filas_aprox
    FROM information_schema.tables
    WHERE table_schema NOT IN ('mysql','information_schema','performance_schema','sys')
    ORDER BY (data_length + index_length) DESC
    LIMIT 15;
  3. 3

    Detect wasted space

    data_free indicates space freed but not returned to the system, typical after many DELETEs. A high value suggests fragmentation.

    SELECT table_name, ROUND(data_free/1024/1024, 1) AS espacio_libre_mb
    FROM information_schema.tables
    WHERE table_schema = 'mi_base' AND data_free > 0
    ORDER BY data_free DESC;

// common mistake

table_rows and the sizes in information_schema are optimizer estimates for InnoDB tables, not exact values. They work very well for trends and comparisons, but do not use them as a precise count; for that use SELECT COUNT(*).

// when it's worth an expert

When disk grows faster than expected, or you cannot tell how long the free space will last, projecting ahead pays off. At dba.mx we set up growth monitoring with early alerts and purge or archiving plans, at a fixed price.

Book an assessment — from USD $550

This guide is for reference and uses example commands. In production, adapt to your version and test in a safe environment first.