MySql DB Table Size

To ensure optimal database performance, you need to identify tables that are consuming excessive memory. These tables might include those with large volumes of data, frequently updated tables, or tables with inefficient queries that require extensive temporary storage.

SELECT 
     table_schema as `Database`, 
     table_name AS `Table`, 
     round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` 
FROM information_schema.TABLES 
ORDER BY (data_length + index_length) DESC;

This SQL query retrieves a list of tables with their total size in MB and in descending order of total size, so you can quickly identify which tables consume the most memory.