Find the size of a MySQL database from CLI

Need: To run a single command in the MySQL console / CLI to show the size of a paricular database.

Solution: This command, when logged in with a user that has permssions to read the information_schema¬†table, substituting “the_database” with the name of the db you want to check (include the double quotes!)

SELECT table_schema "the_database", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MiB" FROM information_schema.TABLES GROUP BY table_schema;

Example result: 

mysql> SELECT table_schema "db", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MiB" FROM information_schema.TABLES GROUP BY table_schema;
+--------------------+-----------------------+
| db                 | Data Base Size in MiB |
+--------------------+-----------------------+
| db                 |            5.53125000 |
| information_schema |            0.18750000 |
+--------------------+-----------------------+
2 rows in set (0.01 sec)

Please let me know if this was useful? Nope, not helpful...Yep, more useful than not! (No Ratings Yet)
Loading...