How to Check MySQL and MariaDB Database Sizes from the Command Line

Updated for 2026: the original snippet answered “how big are my databases?” with one query and a typo. The query was a good start — here’s the complete set, for MySQL 8 and MariaDB 10.x, straight from information_schema.

Size of every database

mysql> SELECT table_schema AS "Database",
         ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) AS "Size (MB)",
         ROUND(SUM(data_free) / 1024 / 1024, 1) AS "Free (MB)"
       FROM information_schema.TABLES
       GROUP BY table_schema
       ORDER BY SUM(data_length + index_length) DESC;

Use / 1024 / 1024 / 1024 if you’d rather have GB. The “Free” column is space allocated to the tables but currently unused — on InnoDB with the shared tablespace it can be misleading, which is why most people run MySQL with innodb_file_per_table on (the default since 5.6).

Biggest tables in one database

mysql> SELECT table_name AS "Table",
         ROUND((data_length + index_length) / 1024 / 1024, 1) AS "Size (MB)",
         table_rows AS "Rows (approx)"
       FROM information_schema.TABLES
       WHERE table_schema = 'your_database'
       ORDER BY (data_length + index_length) DESC
       LIMIT 20;

This is the query that answers the real question behind the question — not “how big is the database” but “what’s eating it”. Nine times out of ten it’s one runaway log, history, or sessions table.

One database, one number

mysql> SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 2) AS "Size (GB)"
       FROM information_schema.TABLES
       WHERE table_schema = 'your_database';

Cross-check against the filesystem

information_schema reports what the engine accounts for; the datadir shows what the disk believes. They should roughly agree:

[root@server ~]# du -sh /var/lib/mysql/*
[root@server ~]# mysql -e "SHOW VARIABLES LIKE 'datadir';"

A database that shrank in SQL but not on disk is usually deleted rows whose space InnoDB hasn’t given back — see OPTIMIZE TABLE (or an ALTER TABLE ... ENGINE=InnoDB rebuild) if you actually need the space back, and expect it to lock while it works.

Notes

  • table_rows for InnoDB is an estimate from the optimizer statistics — fine for spotting the whale, wrong for billing.
  • Everything above works identically on MariaDB; the schema and table names are the same.
  • No shell access? All of it is plain SQL — it runs from phpMyAdmin or any MySQL client, with any account that can see the databases in question.

Running your own server? These guides assume you have a Linux box somewhere — see our guide to choosing a VPS in 2026 for the 7 specs that actually matter before you spin one up.

Scroll to Top