Open In App

Checking MySQL Database Size in Linux

Last Updated : 11 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Mysql is the most popular open-source database among developers. It is developed and managed by Oracle Corporation and initially released on 23 May 1995. It is compatible with each operating system, Like(Linux, Windows, and macOS) which is major support for web-based applications. In this article, we are going to see how to get the size of a database in MySQL in Linux. Every operating system follows the same approach(Syntax) to check the size of a database. 

So let’s see the approach in step-wise:

Step 1: Check your MySql is installed or not.

mysql --version

Step 2: Start MySql.

sudo mysql

Step 3: Check the databases.

show databases;

Step 4: Check the all databases.

Here we define the table_schema and show the size of our database in a new column by following commands:

SELECT table_schema "Database_Name"
SUM(data_length + index_length) / (1024 * 1024) "Database Size in MB"
FROM information_schema.TABLES
GROUP BY table_schema;

Output:

Step 5: Check single databases.

Here we define the table_schema and show the size of any one database (students) in a new column by following commands:

SELECT table_schema "Database_Name",
SUM(data_length + index_length) / (1024 * 1024) "Database Size in MB"
FROM information_schema.TABLES
WHERE table_schema = "students"
ORDER BY (data_length + index_length) DESC;


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads