How to get the size of a MySQL database?

From the control panel interface

If you have access to a control panel like cPanel, DirectAdmin etc, the easiest way is to check the MySQL section. For example, in cPanel, simply navigate to MySQL® Databases section and you will see the size of your databases:

database size1

From the phpMyAdmin interface

phpMyAdmin is a powerful MySQL/MariaDB management tool. Most web hosting control panel comes with phpMyAdmin, but you can also install it yourself on your account. It will show many details about your databases:

database size2

From the command-line

To get the size of all databases on the server, use:

# mysql -e 'SELECT table_schema AS "Database name", round(SUM(data_length + index_length) / 1024 / 1024,2) AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema;'
root@web [~]# mysql -e 'SELECT table_schema AS "Database name", round(SUM(data_length + index_length) / 1024 / 1024,2) AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema;'
+------------------------------------+-----------+
| Database name                      | Size (MB) |
+------------------------------------+-----------+
| abopialo_wp329                     |      6.71 |
| adoptwes_wp645                     |     92.27 |
| azlsiwor_atut487                   |      0.76 |
| azlsiwor_cham191                   |     10.14 |
| ipplothost_wp781                   |      0.12 |
+------------------------------------+-----------+

To get the exact value, remove the round() function from the command.

To get the size of all tables from a specific database, use:

# mysql -e '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_here<-";'
root@web [~]# mysql -e 'SELECT table_name AS "Table", ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)" FROM information_schema.TABLES WHERE table_schema = "ipplothost_wp781";'
+-------------------------+-----------+
| Table                   | Size (MB) |
+-------------------------+-----------+
| wptj_term_relationships |      0.00 |
| wptj_options            |      0.03 |
| wptj_comments           |      0.01 |
| wptj_posts              |      0.02 |
| wptj_usermeta           |      0.01 |
| wptj_term_taxonomy      |      0.00 |
| wptj_terms              |      0.01 |
| wptj_users              |      0.01 |
| wptj_links              |      0.00 |
| wptj_termmeta           |      0.00 |
| wptj_commentmeta        |      0.00 |
| wptj_postmeta           |      0.01 |
+-------------------------+-----------+

Leave a Reply