查询所有数据库的总大小

方法如下:

mysql> use information_schema;mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES;+-----------+| data   |+-----------+| 3052.76MB |+-----------+1 row in set (0.02 sec)

每张表数据量=AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH

SELECTSUM(AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH)/1024/1024 AS total_mbFROM information_schema.TABLES 
SELECTtable_schema,SUM(AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH)/1024/1024 AS total_mbFROM information_schema.TABLES group by table_schema;
mysql> use information_schema;mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='test';+----------+| data   |+----------+| 142.84MB |+----------+1 row in set (0.00 sec)
selecttable_schema as '数据库',sum(table_rows) as '记录数',sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'from information_schema.tablesgroup by table_schemaorder by sum(data_length) desc, sum(index_length) desc;
selecttable_schema as '数据库',table_name as '表名',table_rows as '记录数',truncate(data_length/1024/1024, 2) as '数据容量(MB)',truncate(index_length/1024/1024, 2) as '索引容量(MB)'from information_schema.tablesorder by data_length desc, index_length desc;
例:查看mysql库容量大小selecttable_schema as '数据库',sum(table_rows) as '记录数',sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'from information_schema.tableswhere table_schema='mysql'; 
例:查看mysql库各表容量大小selecttable_schema as '数据库',table_name as '表名',table_rows as '记录数',truncate(data_length/1024/1024, 2) as '数据容量(MB)',truncate(index_length/1024/1024, 2) as '索引容量(MB)'from information_schema.tableswhere table_schema='mysql'order by data_length desc, index_length desc;

直接用shell命令统计mysql data目录中的大小(注意只有库,不包含数据库日志大小)

备注 :

data_length :存储数据大小

data_length/1024/1024:将字节转换为MB

round(sum(data_length/1024/1024),2):取两位小数

concat(round(sum(data_length/1024/1024),2),'MB') :给计算结果追加单位 “MB”

更多相关文章

  1. 发现 developer.android.com 官网的一个单词错误:
  2. 背部如何画好?动漫人物背部画法步骤
  3. android 命令(adb shell)进入指定模拟器或设备
  4. Android--WebView+HTML+Javascript
  5. Android绘制简单折线图的步骤
  6. Android(安卓)Junit 单元测试步骤
  7. Android(安卓)TextToSpeech语音播放文本
  8. Android中LiveData+Room+Paging简单实现步骤
  9. android sdk支持ant自动构建jar步骤

随机推荐

  1. Android Studio 官方示例源码地址
  2. android:layout_marginLeft 与 android:l
  3. RelativeLayout常用属性介绍-----开发日
  4. Android Intent 用法汇总
  5. Android学习—— Android资料之-系统自带
  6. Android ImageButton android:scaleType
  7. Android: WebView tips & tricks
  8. android广播动态注册与发送流程分析
  9. Android(安卓)核心分析 之六 -----IPC框
  10. Android EditText进入页面不聚焦设置(进入