Home  >  Article  >  Database  >  How to Determine the Size of a Specific MySQL Database?

How to Determine the Size of a Specific MySQL Database?

Barbara Streisand
Barbara StreisandOriginal
2024-11-21 17:36:14942browse

How to Determine the Size of a Specific MySQL Database?

Determining the Size of a MySQL Database

Often, it is necessary to determine the size of a MySQL database to assess storage requirements or optimize performance.

Problem: You need to calculate the size of a specific MySQL database, such as "v3."

Solution:

To obtain the database size, execute the following 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 retrieves data from the information_schema.tables table. The table_schema column specifies the database name, and the expression ROUND(SUM(data_length index_length) / 1024 / 1024, 1) calculates the size of the database in megabytes (MB), rounded to one decimal place. The results are grouped by database name.

For the database named "v3," the query would return a row with the database size in MB. For comprehensive instructions and additional insights, refer to the MySQL forums.

The above is the detailed content of How to Determine the Size of a Specific MySQL Database?. 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