PASSWORD RESET

Your destination for complete Tech news

How to get the size of a MYSQL database?

554 0
< 1 min read

To get the size of a MySQL database, you can use the SELECT statement with the SUM() function to sum the sizes of all the tables in the database.

Here’s an example of how to get the size of a MySQL database named database_name:

SELECT SUM(data_length + index_length) AS 'size'
FROM information_schema.TABLES
WHERE table_schema = 'database_name';

In this example, we use the information_schema.TABLES table to get the sizes of all the tables in the database_name database. We use the SUM() function to sum the data_length and index_length columns for each table, and we alias the resulting sum as size.

This will return the total size of the database_name database in bytes.

You can also use the SHOW TABLE STATUS statement to get the sizes of all the tables in a database:

SHOW TABLE STATUS FROM database_name;

This will return a list of all the tables in the database_name database, along with their sizes and other information.

To get the size of an individual table in a database, you can use the SELECT statement with the SUM() function to sum the data_length and index_length columns for the table:

SELECT SUM(data_length + index_length) AS 'size'
FROM information_schema.TABLES
WHERE table_schema = 'database_name' AND table_name = 'table_name';

This will return the size of the table_name table in the database_name database in bytes.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.