SELECT TABLE_NAME,DATA_LENGTH,INDEX_LENGTH,(DATA_LENGTH+INDEX_LENGTH) as length, \
TABLE_ROWS,concat(round((DATA_LENGTH+INDEX_LENGTH)/1024/1024,3), 'MB') as total_size \
FROM information_schema.TABLES WHERE TABLE_SCHEMA='database_name' order by length desc;
information_schema :是mysql⾃带的,它提供了访问数据库元数据的⽅式,元数据是关于数据的数据,
如数据库名或表名,列的数据类型,或访问权限等。有些时候⽤于表述该信息的其他术语包括“数据词典”和“系统⽬录”。
⼀个表占⽤空间的⼤⼩,相当于是 数据⼤⼩ + 索引⼤⼩;
mysql> SELECT TABLE_NAME,DATA_LENGTH,INDEX_LENGTH,(DATA_LENGTH+INDEX_LENGTH) as length,\
-> TABLE_ROWS,concat(round((DATA_LENGTH+INDEX_LENGTH)/1024/1024,3), 'MB') as total_size \
-> FROM information_schema.TABLES WHERE TABLE_SCHEMA='zhcwsystem' order by length desc;
+---------------------------------+-------------+--------------+------------+------------+------------+
| TABLE_NAME | DATA_LENGTH | INDEX_LENGTH | length | TABLE_ROWS | total_size |
+---------------------------------+-------------+--------------+------------+------------+------------+
| tab_lottery_spinfo_bd | 7332730928 | 489879552 | 7822610480 | 31176968 | 7460.223MB |
| tab_kaijiang_info | 130711552 | 16269312 | 146980864 | 853084 | 140.172MB |
| tab_lottery_match_bd | 55002516 | 3718144 | 58720660 | 271763 | 56.000MB |
| tab_lottery_result_bd | 16977364 | 10750976 | 27728340 | 276547 | 26.444MB |
| tab_cz_zj_info | 18198416 | 607232 | 18805648 | 26841 | 17.934MB |
| tab_lottery_result | 6447924 | 3440640 | 9888564 | 120396 | 9.430MB |
| tab_sport_lottery_info | 5374524 | 1154048 | 6528572 | 39045 | 6.226MB |
| tab_cz_dq_info | 5115396 | 424960 | 5540356 | 8684 | 5.284MB |
| tab_nb_detail | 56 | 2048 | 2104 | 1 | 0.002MB |
| tab_cz_type | 40 | 2048 | 2088 | 2 | 0.002MB |
| tab_lottery_result_lancai_copy1 | 0 | 2048 | 2048 | 0 | 0.002MB |
| tab_lottery_result_lancai_copy | 0 | 2048 | 2048 | 0 | 0.002MB |