Skip to content

Instantly share code, notes, and snippets.

@ronaldbradford
Created December 20, 2022 21:12
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 ronaldbradford/bd3ca43c1cc2481b044a3a33fbfe3bf4 to your computer and use it in GitHub Desktop.
Save ronaldbradford/bd3ca43c1cc2481b044a3a33fbfe3bf4 to your computer and use it in GitHub Desktop.
Gather details of the largest tables in a given MySQL schema.
# Connect to your schema first, i.e. USE <schema>
SELECT if(length(table_name)>40,concat(left(table_name,38),'..'),table_name) AS table_name,
engine,row_format as format, table_rows, avg_row_length as avg_row,
round((data_length+index_length)/1024/1024,2) as total_mb,
round((data_length)/1024/1024,2) as data_mb,
round((index_length)/1024/1024,2) as index_mb
FROM information_schema.tables
WHERE table_schema=DATABASE()
ORDER BY 6 DESC;
# Schema Table BLOB/TEXT Usage
SELECT table_schema,table_name,column_name,data_type
FROM information_schema.columns
WHERE table_schema= DATABASE()
AND ( data_type LIKE '%TEXT' OR data_type like '%BLOB');
# Large varchars
SELECT table_schema,table_name,column_name,character_maximum_length
FROM information_schema.columns
WHERE data_type='varchar'
AND character_maximum_length > 255
AND table_schema = DATABASE();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment