Skip to content

Instantly share code, notes, and snippets.

@v0112358
Created March 25, 2020 14:26
Show Gist options
  • Save v0112358/b564c94d6a21cf08c7aaf285e72dae35 to your computer and use it in GitHub Desktop.
Save v0112358/b564c94d6a21cf08c7aaf285e72dae35 to your computer and use it in GitHub Desktop.
useful mysql queries

1/ Check index size

SELECT concat(table_schema,'.',table_name) tables,
concat(round(table_rows/1000000,2),'M') rows,
concat(round(data_length/(1024*1024*1024),2),'G') data_size,
concat(round(index_length/(1024*1024*1024),2),'G') index_size,
concat(round((data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(index_length/data_length,2) index_data_ratio
FROM information_schema.TABLES
WHERE table_name like "%PRIVILEGES%"
ORDER BY total_size DESC LIMIT 20;

2/ Find database size in your MySQL instance

SELECT table_schema AS "Database",
         ROUND(SUM(data_length + index_length) / 1024 / 1024,2) AS "Size (MB)"
FROM information_schema.TABLES
GROUP BY  table_schema;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment