Admin-Ahead Community

General Category => General Discussion => Topic started by: sajay on November 06, 2013, 11:10:01 pm

Title: mySQL command to print the Database Size.
Post by: sajay on November 06, 2013, 11:10:01 pm

 Using this mySQL query we can view the size of Databases :

 1.Login to the server
 2.Enter in to the mySQL prompt

Execute the following command

  mysql> SELECT table_schema "DB Name", Round(Sum(data_length + index_length)  / 1024, 2) "DB Size in KB"  FROM   information_schema.tables  GROUP  BY table_schema;

+--------------------+---------------+
| DB Name            | DB Size in KB |
+--------------------+---------------+
| information_schema  |          8.00 |
| joomla                       |       3808.00 |
| mysql                        |        655.79 |
| sched                        |          8.02 |
| shift                          |         44.18 |
| wp                            |        439.70 |
+--------------------+---------------+
6 rows in set (0.02 sec)

If you want to print the Database size in MB

mysql> SELECT table_schema "DB Name", Round(Sum(data_length + index_length)/1024 /1024, 1) "DB Size in MB"  FROM   information_schema.tables  GROUP  BY table_schema;
+--------------------+---------------+
| DB Name            | DB Size in MB |
+--------------------+---------------+
| information_schema |   0.0 |
| joomla              |           3.7        |
| mysql                |           0.6        |
| sched               |           0.0         |
| shift                 |            0.0         |
| wp                   |            0.4         |
+--------------------+---------------+
6 rows in set (0.02 sec)