Skip to content

Instantly share code, notes, and snippets.

@kangmasjuqi
Last active September 7, 2018 03:09
Show Gist options
  • Save kangmasjuqi/b63a44e940eb917a0578cc16ce040509 to your computer and use it in GitHub Desktop.
Save kangmasjuqi/b63a44e940eb917a0578cc16ce040509 to your computer and use it in GitHub Desktop.
view statictic/ highlight/ summary of mysql database
mysql -uroot
--
-- SHOW TABLES SIZE OF EACH DATABASES
--
SELECT
table_schema as `Database`,
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
WHERE table_schema<>'mysql' and table_schema<>'information_schema' and round(((data_length + index_length) / 1024 / 1024), 2) > 0
ORDER BY (data_length + index_length) DESC;
--
-- SHOW DATABASES SIZE
--
SELECT table_schema "DB Name", ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"
FROM information_schema.tables GROUP BY table_schema;
--
-- SHOW DATABASES AND THEIR NUMBER OF TABLES
--
select table_schema, count(1)
from information_schema.tables
WHERE table_schema<>'mysql' and table_schema<>'information_schema' and table_schema<>'performance_schema'
group by table_schema;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment