Skip to content

Instantly share code, notes, and snippets.

@aabumuslimov
Last active August 12, 2024 11:31
Show Gist options
  • Save aabumuslimov/58ee86e244bbc331084b285fe8a72e27 to your computer and use it in GitHub Desktop.
Save aabumuslimov/58ee86e244bbc331084b285fe8a72e27 to your computer and use it in GitHub Desktop.
(SELECT "DB Total" AS "Table",
'' AS 'Engine',
ROUND(SUM(data_length) / 1048576) AS 'Data',
ROUND(SUM(index_length) / 1048576) AS 'Index',
ROUND(SUM(data_length + index_length) / 1048576) AS 'Total',
ROUND(SUM(data_free) / 1048576) AS 'Free'
FROM information_schema.TABLES
WHERE table_schema = DATABASE())
UNION ALL
(SELECT
table_name,
engine,
IF(data_length > 0 AND data_length < 52429, 0.1, ROUND(data_length / 1048576, 1)),
IF(index_length > 0 AND index_length < 52429, 0.1, ROUND(index_length / 1048576, 1)),
IF(data_length + index_length > 0 AND data_length + index_length < 52429, 0.1, ROUND((data_length + index_length) / 1048576, 1)),
ROUND(data_free / 1048576, 1)
FROM information_schema.TABLES
WHERE table_schema = DATABASE())
ORDER BY total DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment