Why Your MySQL Dump Is Smaller Than Your DB Data Directory

Why Your MySQL Dump Is Smaller Than Your DB Data Directory

QuoteBefore every deployment or any database changes, you always take a database backup. Sometimes, when you compare the size of that backup file to the database directory on disk (/var/lib/mysql), you’ll often see a big difference. A smaller dump and a larger data folder are perfectly normal. Your dump command isn’t wrong.

1. Why Dump Files Are Smaller Than Disk Usage

What mysqldump Exports

  • Schemas: only the CREATE TABLE statements

  • Raw row data: only the INSERT statements

  • Nothing else: no indexes, no transaction logs, no engine metadata

What Lives in /var/lib/mysql/dbname/

  • Data files

    • InnoDB tablespaces (*.ibd)

    • MyISAM data files (*.MYD)

  • Indexes

    • B-tree structures for fast lookups (*.MYI for MyISAM; built into .ibd for InnoDB)

  • Logs & Overhead

    • Undo/redo logs, binary logs (if enabled)

    • Storage-engine metadata and page headers

  • Unused fragmented space

    • Gaps left inside data files by deletes or updates, not returned to the OS


Notes

Example : The MySQL dump is only 96MB and the size of the database directory path is 230MB (/var/lib/mysql/prod_orangehrm)


            dump = essentials

            data folder = essentials + indexes + logs + fragmentation.


2. Key Concepts

Compression - InnoDB can compress pages on disk to save space, but dump files remain plain-text SQL.
Fragmentation - Gaps inside data files created by deletes/updates; these gaps bloat the file size until reclaimed

Quote
With this little knowledge, you’ll understand why your backups look smaller and how the MySQL data directory grows.