mysql>   
mysql> use information_schema ;  /*切换到information_schema数据下*/     
Database changed  
mysql>   
mysql> select concat(round(sum(data_length/1024/1024),2),\'MB\') as data from tables;  /*查询所有数据大小*/     
+----------+  
| data     |  
+----------+  
| 123.68MB |  
+----------+  
1 row in set (0.36 sec)  
  
mysql> select concat(round(sum(data_length/1024/1024),2),\'MB\') as data from tables where table_schema=\'hrkip\';  /*查询数据库名称为“hrkip”的数据大小*/   
+--------+  
| data   |  
+--------+  
| 8.65MB |  
+--------+  
1 row in set (0.00 sec)  
  
mysql> select concat(round(sum(data_length/1024/1024),2),\'MB\') as data from tables where table_schema=\'hrkip\' and table_name=\'jx_lsjl\' ;  /*查询数据库名称为“hrkip”,表名为“ jx_lsjl”的数据大小*/   
+--------+  
| data   |  
+--------+  
| 6.77MB |  
+--------+  
1 row in set (0.00 sec)  
  

 

备注 :

data_length :存储数据大小

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

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

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

版权声明:本文为weifeng1463原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/weifeng1463/p/9222047.html