Запрос для расчета размера таблиц начиная с MySQL 5.0:
use information_schema;
SELECT concat(table_schema,'.',table_name),concat(round(table_rows/1000000,2),'M') rows,
concat(round(data_length/(1024*1024*1024),2),'G') DATA,
concat(round(index_length/(1024*1024*1024),2),'G') idx,
concat(round((data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(index_length/data_length,2) idxfrac
FROM TABLES ORDER BY data_length+index_length DESC LIMIT 10;
| concat(table_schema,'.',table_name) | rows | DATA | idx | total_size | idxfrac |
| art87.link_out87 | 37.25M | 14.83G | 14.17G | 29.00G | 0.96 |
#
| art87.article87 | 12.67M | 15.83G | 4.79G | 20.62G | 0.30 |
Определение числа таблиц, суммарного размера строк, данных и индексов:
SELECT count(*) TABLES,
concat(round(sum(table_rows)/1000000,2),'M') rows,
concat(round(sum(data_length)/(1024*1024*1024),2),'G') DATA,
concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(sum(index_length)/sum(data_length),2) idxfrac
FROM information_schema.TABLES;
| TABLES| rows | DATA | idx | total_size | idxfrac |
| 1538 | 1623.91M | 314.00G | 36.86G | 350.85G | 0.12 |
После "FROM information_schema.TABLES" можно добавить дополнительный фильтр,
например вывести информацию только для таблиц performance_log:
... WHERE table_name LIKE "%performance_log%";
Определение самых больших таблиц в БД:
SELECT
count(*) TABLES,
table_schema,concat(round(sum(table_rows)/1000000,2),'M') rows,
concat(round(sum(data_length)/(1024*1024*1024),2),'G') DATA,
concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(sum(index_length)/sum(data_length),2) idxfrac
FROM information_schema.TABLES
GROUP BY table_schema
ORDER BY sum(data_length+index_length) DESC LIMIT 10;
|TABLES| table_schema | rows | DATA | idx | total_size | idxfrac |
| 48 | cacti | 0.01M | 0.00G | 0.00G | 0.00G | 0.72 |
| 17 | mysql | 0.00M | 0.00G | 0.00G | 0.00G | 0.18 |
Объем данных в разрезе типа хранилища:
SELECT engine,
count(*) TABLES,
concat(round(sum(table_rows)/1000000,2),'M') rows,
concat(round(sum(data_length)/(1024*1024*1024),2),'G') DATA,
concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(sum(index_length)/sum(data_length),2) idxfrac
FROM information_schema.TABLES
GROUP BY engine
ORDER BY sum(data_length+index_length) DESC LIMIT 10;
| engine | TABLES | rows | DATA | idx | total_size | idxfrac |
| MyISAM | 1243 | 941.06M | 244.09G | 4.37G | 248.47G | 0.02 |
| InnoDB | 280 | 682.82M | 63.91G | 32.49G | 96.40G | 0.51 |
| MRG_MyISAM| 1 | 13.66M | 6.01G | 0.00G | 6.01G | 0.00 |
| MEMORY | 14 | 0.00M | 0.00G | 0.00G | 0.00G | NULL |
|