MYSQL查看所有数据库容量大小/表占用

方法一:

  1. SELECT sum(DATA_LENGTH)+sum(INDEX_LENGTH)
  2. FROM information_schema.TABLES<br>&nbsp;where TABLE_SCHEMA='oa_api';

方法二:

  1. select
  2. table_schema as '数据库',
  3. sum(table_rows) as '记录数',
  4. sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',
  5. sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'
  6. from information_schema.tables
  7. group by table_schema
  8. order by sum(data_length) desc, sum(index_length) desc;

指定表占用空间

  1. SELECT table_name AS `Table`,
  2. ROUND(((data_length + index_length) / 1024 / 1024), 2) AS `Size (MB)`
  3. FROM information_schema.TABLES
  4. WHERE table_schema = 'abc'
  5. AND table_name = 'tp_test';
  6. 或者:
  7. SELECT table_name AS `Table`,
  8. ROUND(((data_length + index_length) / 1024 / 1024), 2) AS `Size(MB)`
  9. FROM information_schema.TABLES
  10. WHERE table_schema = 'oa_api'
  11. order by `Size(MB)` desc;

查询指定数据库的所有表的容量占用大小:

  1. 开启profiles
  2. mysql&gt; set profiling=1;
  3. SELECT TABLE_NAME,DATA_LENGTH+INDEX_LENGTH as '表大小',TABLE_ROWS FROM information_schema.TABLES WHERE TABLE_SCHEMA='djjf_api' order by 表大小 desc;

查询剖析工具:show profile;
查询语句分析工具(包括索引):explain select * from artist