Get MySQL Database Size from Terminal

If you need to find out the size of MySQL databases you use from terminal, the following query will list all the databases with their respective sizes:

mysql> SELECT table_schema "database", sum(data_length + index_length)/1024/1024 "size in MB" FROM information_schema.TABLES GROUP BY table_schema;

The result you’ll get will be something like:

| database           | size in MB     |
+--------------------+----------------+
| test1              | 13542.68241349 | 
| test2              |  1522.23837675 | 
| test3              | 26532.27326164 | 
| information_schema |     0.00390626 | 
+--------------------+----------------+
4 rows in set (0.02 sec)

If you have large databases, you can show the result in gigabytes with this query:

mysql> SELECT table_schema "database", sum(data_length + index_length)/1024/1024/1024 "size in GB" FROM information_schema.TABLES GROUP BY table_schema;

If you liked the post, we should get connected - follow me on Twitter