Home >Database >Mysql Tutorial >How to Determine the Size of a Specific Database in MySQL?

How to Determine the Size of a Specific Database in MySQL?

DDD
DDDOriginal
2024-11-17 18:07:02280browse

How to Determine the Size of a Specific Database in MySQL?

Determining Database Size in MySQL

In MySQL, obtaining the size of a database is a valuable operation for storage planning and optimization. Here's a simple approach to retrieve the size of a specific database:

To determine the size of the "v3" database, execute the following SQL query:

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;

This query leverages tables in information_schema, particularly tables, to gather information about the database tables. The SUM() function is used to aggregate the data_length and index_length values, which represent the size of the table data and indexes, respectively. The result is then divided by 1024 twice to convert it into megabytes (MB).

Upon executing this query, you will get a table displaying individual database names and their corresponding sizes in megabytes. You can identify the entry for the "v3" database to obtain its size.

This query was derived from the MySQL forums, where additional instructions and insights can be found.

The above is the detailed content of How to Determine the Size of a Specific Database in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn