使用SQL命令查看MYSQL数据库大小

时间:2021-09-06 01:23:30
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”