Find MySQL Database and Table Size

To find the size of databases using SQL command, run the following SQL in MySQL prompt.

SELECT table_schema AS "Database", ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema;

Example

MySQL database disk usage

FInd disk usage by tables

To find disk usage by tables in database, run

SELECT table_name AS "Table", round(((data_length + index_length) / 1024 / 1024), 2) as "size (MB)" FROM information_schema.TABLES WHERE table_schema = "DB_NAME_HERE"  ORDER BY data_length DESC;

In the above SQL, replace DB_NAME_HERE with the actual name of the database.

Example

SELECT table_name AS "Table", round(((data_length + index_length) / 1024 / 1024), 2) as "size (MB)" FROM information_schema.TABLES WHERE table_schema = "xogifts_db"  ORDER BY data_length DESC;
MySQL table disk usage

See MySQL

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *