MySQL commands

Here are some of the common commands in MySQL:

1. To get the size(in mb) of the tables in a database:
SELECT 
    table_name AS `Table`, 
    ROUND(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` 
FROM information_schema.TABLES 
WHERE table_schema = "db-name"
    
2. To get the size(in mb) of the indexes in a table:
SELECT database_name, table_name, index_name,
ROUND(stat_value * @@innodb_page_size / 1024 / 1024, 2) size_in_mb
FROM mysql.innodb_index_stats
WHERE stat_name = 'size' AND index_name != 'PRIMARY' AND database_name = "db-name" AND table_name = "table-name"
ORDER BY size_in_mb DESC;

By Abhishek Jain

Techie with 10+ years of experience and counting.

Leave a comment

Your email address will not be published. Required fields are marked *