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!