Mysql - How to find size of database, Query to find size of table

How to find size of database

How to find the size of a database and table

You can find the find the database size, specific tables size using the following queries. Earlier I use to make blunder and assume the database size by calculating the /var/lib/mysql/dbfolder folder or directory. But actually you have to calculate the size of a database by calculating its data length and index length.

Get Size of all database tables
SELECT TABLE_SCHEMA AS 'Database', TABLE_NAME AS 'Table',
CONCAT(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE)/1024/1024),2),"Mb")
AS Size FROM INFORMATION_SCHEMA.TABLES;

Get Size of specific database tables
SELECT TABLE_SCHEMA AS 'Database', TABLE_NAME AS 'Table',
CONCAT(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE)/1024/1024),2),"MB")
AS Size FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA like '%YOUR_DB_NAME%';

Get size of entire DB
SELECT CONCAT(sum(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE)/1024/1024),2)),"MB")
AS Size FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA like '%YOUR_DB_NAME%';

Replace YOUR_DB_NAME with your database name and TABLE_NAME with your table name to find the size of the database or table.

The topic on Mysql - How to find size of database is posted by - Steve

Hope you have enjoyed, Mysql - How to find size of databaseThanks for your time

Tech Bluff