TailTemplate Build stunning websites faster with our pre-designed Tailwind CSS templates

MySQL commands for checking database size

In this tutorial, we will introduce some MySQL commands related to database sizes. They are super handy when you need to quickly find out database storage.

Check database size

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

Sort database table by size

SELECT
	table_schema AS `Database`,
	table_name AS `Table`,
	round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM
	information_schema.TABLES
ORDER BY
	(data_length + index_length)
	DESC;

Fetch database table columns

Replace your_table_name with your desired database name.

SELECT COLUMN_NAME 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE 
    TABLE_SCHEMA = Database()
AND TABLE_NAME = 'your_table_name' ;