Home > Database > Mysql Tutorial > body text

How Do I Determine the Size of a MySQL Database?

Mary-Kate Olsen
Release: 2024-11-17 12:33:02
Original
563 people have browsed it

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; 
Copy after login

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        |
+----------+---------------+
Copy after login

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

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

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template