Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benklocek/fdca1a51d498abd5afb5f377530c607b to your computer and use it in GitHub Desktop.
Save benklocek/fdca1a51d498abd5afb5f377530c607b to your computer and use it in GitHub Desktop.
Useful SQL Queries
#Get the size of each table, ordered by largest to smallest
SELECT table_name AS "Tables",
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = "YOU+TABLE+NAME+HERE"
ORDER BY (data_length + index_length) DESC;
#Get the size of the entire DB
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
#Get the size of each option sorted by size for wp_options ( props @jtsternberg )
SELECT
opts.option_id 'Option ID',
opts.option_name 'Option Name',
LENGTH(opts.option_value) "Size in bytes",
round(((length(opts.option_value)) / 1024), 2) "Size in KB",
round(((length(opts.option_value)) / 1024 / 1024), 2) "Size in MB"
FROM
wp_options opts
ORDER BY CHAR_LENGTH(option_value) DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment