Calculating the Size of MySQL/MariaDB Database Console

Your Text In this tutorial, I will provide information on how to calculate the size of a database using the MySQL Console. This function is useful when we want to compare the size of the database after the dump/restore process from the old server to the new server. This command has been tested with MySQL version 5.7 and above or MariaDB version 10 and above. Currently, I am using MySQL version 8 – mysql Ver 8.0.12 for Linux on x86_64 (MySQL Community Server – GPL) for this trial.

Login to MySQL Console:
mysql -u root
login-mysql.png

Run the following command in your MySQL Console:
SELECT table_schema AS "Database Name", ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size in (MB)" FROM information_schema.TABLES GROUP BY table_schema;

Here is an example of the database calculation results in MegaByte units.
mysqldb.png

Note:

  1. Calculation results are in MB
  2. Based on my experience, the size of the database may vary due to different MySQL versions.
Load comments

Read more