how to check database size in mysql1 min read

We need your support!!
Other Amount:
techrunnr.com:
24-Hour Flash Sale. Courses from just ₹ 490.
Prabhin Prabharkaran Administrator
DevOps Engineer

He is a Technical professional. He is a person who loves to share tricks and tips on the Internet. He Posts what he does!

follow me

Hi Techrunnr Readers, this document deals with how to check database size in mysql.
MySQL is an open-source relational database management system. Its name is a combination of “My”, the name of co-founder Michael Widenius’s daughter, and “SQL”, the abbreviation for Structured Query Language.

It’s very biggest headache for database administrators/sysadmin to check the database size. Here is the solution for that. Perform the following steps to get size if of databases in Mysql or MariaDB.

1. Login to mysql

mysql -u root -p

2. Execure the following query to get the size.

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; 

Here is the expected output for the above query.


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 |
+--------------------+---------------+
| news               |           0.8 |
| information_schema |           0.2 |
| mysql              |           2.5 |
| performance_schema |           0.0 |
| techrunnr          |          10.8 |
| sys                |           0.0 |
+--------------------+---------------+
6 rows in set (0.22 sec)

You can alter the above query to get size in GB etc.

Have good learning

We need your support!!
Other Amount:
techrunnr.com:
#1
#2
#3
Questions Answered
Articles Written
Overall Points

Prabhin Prabharkaran

He is Technical professional. He is a person who loves to share tricks and tips on the Internet. He Posts what he does!!

You may also like...

Leave a Reply