"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How Do I Determine the Size of a MySQL Database?

How Do I Determine the Size of a MySQL Database?

Published on 2024-12-21
Browse:664

How Do I Determine the Size of a MySQL Database?

Determining MySQL Database Size

When working with MySQL, it's often necessary to ascertain the size of a specific database. One such scenario arises when a database named "v3" needs to be sized.

Query to Retrieve Database Size

The following SQL query can be executed to retrieve the size of the database in megabytes:

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; 

Understanding the Query

  • table_schema: This field represents the database name.
  • SUM(data_length index_length): This calculates the total size of all tables' data and indexes in bytes.
  • ROUND(... / 1024 / 1024, 1): This rounds the result to one decimal place and converts it from bytes to megabytes (MB).

Example Output

For the "v3" database, the query might return an output similar to:

 ---------- --------------- 
| DB Name   | DB Size in MB |
 ---------- --------------- 
| v3        |  28.5        |
 ---------- --------------- 

This indicates that the "v3" database is approximately 28.5 megabytes in size.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3