Check size of database and table in MySQL

Check size of database and table in MySQL

Check the size of database in MySQL

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

-- In GB
SELECT table_schema AS "Database", SUM(data_length + index_length ) /1024/1024/1024 AS "Size (GB)" FROM information_schema.TABLES GROUP BY table_schema

Check Size of tables in MySQL

--Exact size of tables in MB
SELECT table_schema "DB Name", table_name,(data_length + index_length)/1024/1024,1 "TableSizeMB" from information_schema.tables where table_schema='mysql' and table_name = 'test';

--Round size of tables in MB
SELECT table_schema "DB Name", table_name,round((data_length + index_length)/1024/1024,1) "TableSizeMB" from information_schema.tables where table_schema='mysql' and table_name = 'test';

--Size in GB
SELECT table_schema "DB Name", table_name,(data_length + index_length)/1024/1024/1024,1 "TableSizeGB" from information_schema.tables where table_schema='mysql' and table_name = 'test';

Note: I used the round function for make it more readable form, for exact size remove round of function from SQL queries.

This entry was posted in MySQL on by .
Unknown's avatar

About SandeepSingh

Hi, I am working in IT industry with having more than 15 year of experience, worked as an Oracle DBA with a Company and handling different databases like Oracle, SQL Server , DB2 etc Worked as a Development and Database Administrator.

Leave a Reply