fbpx

MySql Database Size

MySql Database Size

This query will get mysql database size in mb. Replace the DATABASE_NAME with actual database name in query below
 

SELECT
	CONCAT(
		sum(
			ROUND(
				(
					(
						database_info.data_lenght + database_info.index_lenght - database_info.data_free_lenght
					) / 1024 / 1024
				),
				2
			)
		),
		" MB"
	) AS Size
FROM
	(
		SELECT
			sum(
				CAST(DATA_LENGTH AS UNSIGNED)
			) AS data_lenght,
			sum(
				CAST(INDEX_LENGTH AS UNSIGNED)
			) AS index_lenght,
			sum(CAST(DATA_FREE AS UNSIGNED)) AS data_free_lenght
		FROM
			INFORMATION_SCHEMA. TABLES
		WHERE
			TABLE_SCHEMA LIKE '%DATABASE_NAME%'
	) AS database_info;

Share this post