Calcular el tamaño de una base de datos y tablas con Information Schema

Aca les dejo na breve y sencilla solucion para poder calcular los tamaños de las DB en MySQL /MariaDB y forks con Information Schema

Realmente es muy sencillo:

MariaDB [information_schema]SELECT table_name, table_rows, data_length, index_length,
-> round(((data_length + index_length) / 1024 / 1024),2) "Size in MB"
-> FROM information_schema.TABLES WHERE table_schema = "training";
+--------------+------------+-------------+--------------+------------+
| table_name   | table_rows | data_length | index_length | Size in MB |
+--------------+------------+-------------+--------------+------------+
| by_year      |          4 |       65536 |            0 |       0.06 |
| country      |          0 |           0 |         1024 |       0.00 |
| part         |          0 |       16384 |            0 |       0.02 |
| soccer_teams |          2 |       16384 |            0 |       0.02 |
| table1       |          0 |           0 |         1024 |       0.00 |
| test_aria    |          0 |        8192 |         8192 |       0.02 |
+--------------+------------+-------------+--------------+------------+
6 rows in set (0.22 sec)

Leave a Reply

Your email address will not be published.