Here’s an quick and easy SQL query for finding the tables that take most space in your database.
SELECT TABLE_NAME, Engine, table_rows, round(((data_length + index_length) / 1024 / 1024),2) 'Size in MB' FROM information_schema.TABLES WHERE TABLE_TYPE='BASE TABLE' AND table_schema='YOUR_DATABASE_NAME' ORDER BY data_length DESC LIMIT 20;
Running a WordPress website? Want to run it in WP CLI? Then use it like:
wp db query "SELECT TABLE_NAME, Engine, table_rows, round(((data_length + index_length) / 1024 / 1024),2) 'Size in MB' FROM information_schema.TABLES WHERE TABLE_TYPE='BASE TABLE' AND table_schema='YOUR_DATABASE_NAME' ORDER BY data_length DESC LIMIT 20;"
Leave a Reply