转载

mysql查询占用空间大小

1、进去指定schema 数据库(存放了其他的数据库的信息)
mysql> use information_schema; Database changed
2、查询所有数据的大小
mysql> select concat(round(sum(DATA_LENGTH/1024/1024), 2), 'MB') -> as data from TABLES; +-----------+ | data | +-----------+ | 6674.48MB | +-----------+ 1 row in set (16.81 sec)
3、查看指定数据库实例的大小,比如说数据库 forexpert
mysql> select concat(round(sum(DATA_LENGTH/1024/1024), 2), 'MB') -> as data from TABLES where table_schema='forexpert'; +-----------+ | data | +-----------+ | 6542.30MB | +-----------+ 1 row in set (7.47 sec)
4、查看指定数据库的表的大小,比如说数据库 forexpert 中的 member 表
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data -> from TABLES where table_schema='forexpert' -> and table_name='member'; +--------+ | data | +--------+ | 2.52MB | +--------+ 1 row in set (1.88 sec)
5、查询占用空间前10名的表
mysql> select table_name,table_rows from tables order by table_rows desc limit 10; +------------------------+------------+ | table_name | table_rows | +------------------------+------------+ | phpbb_search_wordmatch | 31661657 | | phpbb_search_wordlist | 935052 | | vg_items_tags_item | 889132 | | vg_items | 204079 | | phpbb_confirm | 120201 | | vg_items_tags | 58489 | | phpbb_user_group | 39948 | | phpbb_sessions | 1037 | | phpbb_users | 994 | | help_relation | 991 | +------------------------+------------+ 10 rows in set
正文到此结束
Loading...