If you use SQL databases in your projects, then it becomes important for you to keep track of your database size in order to plan for database upscaling needs in future. But do you know how to check the size of your various database schemas.
To calculate the storage size of database in MySQL or PostgreSQL, follow these steps:
1. Login to your MySQL database console.
If you are using linux terminal then, you can login with below commands:
$ sudo mysql –u root –p
Enter your root password and hit enter, you will get logged in and SQL console will appear.
In case you are using Windows, you can login to your favorite SQL editor such as MySQL workbench.
2. Enter the following SQL query in your SQL console and hit enter:
SELECT table_schema AS 'Database',
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Size (MB)'
FROM information_schema.TABLES
GROUP BY table_schema;
System will return the result with a table listing down the Database schema and its corresponding size in MB.
This query basically goes to the Information_schema’s TABLES. In this table, there are multiple columns, one of which is “data_length” and “index_length”.
This query takes the sum of the sizes given in both the columns and then convert it into MB. Then it returns the summary by grouping them based on the different table schema present in the database.
I hope you will find this useful. Do share this post among your network.
Streamline your sales process and increase productivity