MySql: Get Database And Tables Size

20 Jul 2020

Tested On

DB: MariaDB-10.2.12

If you have size issue with your mysql server and you want to understand which database or tables consume all the space you can use the following queries:

SELECT table_schema AS "Database",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"
FROM information_schema.TABLES
GROUP BY table_schema;
SELECT table_name AS "Table",
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.TABLES
WHERE table_schema = "database_name"
ORDER BY (data_length + index_length) DESC;

don’t forget to change “database_name” with the correct database name

Notes