自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

MySQL查看表占用空間大小

數(shù)據(jù)庫 MySQL
在mysql中有一個默認的數(shù)據(jù)表information_schema,information_schema這張數(shù)據(jù)表保存了MySQL服務器所有數(shù)據(jù)庫的信息。如數(shù)據(jù)庫名,數(shù)據(jù)庫的表,表欄的數(shù)據(jù)類型與訪問權限等。

[[377200]]

 前言

在mysql中有一個默認的數(shù)據(jù)表information_schema,information_schema這張數(shù)據(jù)表保存了MySQL服務器所有數(shù)據(jù)庫的信息。如數(shù)據(jù)庫名,數(shù)據(jù)庫的表,表欄的數(shù)據(jù)類型與訪問權限等。

再簡單點,這臺MySQL服務器上,到底有哪些數(shù)據(jù)庫、各個數(shù)據(jù)庫有哪些表,每張表的字段類型是什么,各個數(shù)據(jù)庫要什么權限才能訪問,等等信息都保存在information_schema表里面,所以請勿刪改此表。

代碼

1,切換數(shù)據(jù)庫

  1. use information_schema; 

2,查看數(shù)據(jù)庫使用大小 

  1. select concat(round(sum(data_length/1024/1024),2),’MB’) as data from tables where table_schema=’DB_Name’ ; 

3,查看表使用大小 

  1. select concat(round(sum(data_length/1024/1024),2),’MB’) as data from tables where table_schema=’DB_Name’ and table_name=’Table_Name’; 

網(wǎng)上找的一個,親測可用:

  •  先進去MySQL自帶管理庫:information_schema
  •  然后查詢 data_length,index_length
  •  你自己的數(shù)據(jù)庫名:dbname
  •  你自己的表名:tablename 
  1. mysql> use information_schema;    
  2. Database changed    
  3. mysql> select data_length,index_length    
  4.     -> from tables where    
  5.     -> table_schema='dbname'    
  6.     -> and table_name = 'tablename';   
  7. +-------------+--------------+    
  8. | data_length | index_length |    
  9. +-------------+--------------+    
  10. |   166379520 |    235782144 |    
  11. +-------------+--------------+    
  12. row in set (0.02 sec)    
  1. mysql> select concat(round(sum(data_length/1024/1024),2),'MB') as data_length_MB,    
  2.     -> concat(round(sum(index_length/1024/1024),2),'MB') as index_length_MB    
  3.     -> from tables where    
  4.     -> table_schema='dbname'    
  5.     -> and table_name = 'tablename';   
  6. +----------------+-----------------+    
  7. | data_length_MB | index_length_MB |    
  8. +----------------+-----------------+    
  9. | 158.67MB       | 224.86MB        |    
  10. +----------------+-----------------+    
  11. row in set (0.03 sec) 

1.查看所有數(shù)據(jù)庫容量大小 

  1. select  
  2. table_schema as '數(shù)據(jù)庫',  
  3. sum(table_rows) as '記錄數(shù)',  
  4. sum(truncate(data_length/1024/1024, 2)) as '數(shù)據(jù)容量(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;  
  9. ```   
  10. ### 2.查看所有數(shù)據(jù)庫各表容量大小  
  11. ```sql  
  12. select  
  13. table_schema as '數(shù)據(jù)庫',  
  14. table_name as '表名',  
  15. table_rows as '記錄數(shù)',  
  16. truncate(data_length/1024/1024, 2) as '數(shù)據(jù)容量(MB)',  
  17. truncate(index_length/1024/1024, 2) as '索引容量(MB)'  
  18. from information_schema.tables  
  19. order by data_length desc, index_length desc; 

3.查看指定數(shù)據(jù)庫容量大小

例:查看mysql庫容量大小 

  1. select  
  2. table_schema as '數(shù)據(jù)庫',  
  3. sum(table_rows) as '記錄數(shù)',  
  4. sum(truncate(data_length/1024/1024, 2)) as '數(shù)據(jù)容量(MB)',  
  5. sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'  
  6. from information_schema.tables  
  7. where table_schema='mysql'

4.查看指定數(shù)據(jù)庫各表容量大小

例:查看mysql庫各表容量大小 

  1. select  
  2. table_schema as '數(shù)據(jù)庫',  
  3. table_name as '表名',  
  4. table_rows as '記錄數(shù)',  
  5. truncate(data_length/1024/1024, 2) as '數(shù)據(jù)容量(MB)',  
  6. truncate(index_length/1024/1024, 2) as '索引容量(MB)'  
  7. from information_schema.tables  
  8. where table_schema='mysql'  
  9. order by data_length desc, index_length desc;  
  1. select concat(round(sum(data_length/1024/1024),2),'MB') as data_length_MB, concat(round(sum(index_length/1024/1024),2),'MB') as index_length_MB  
  2. from tables  
  3. where table_schema='passport' and table_name='tb_user_info'

-- 569.98MB 141.98MB 

  1. select concat(round(sum(data_length/1024/1024),2),'MB') as data_length_MB, concat(round(sum(index_length/1024/1024),2),'MB') as index_length_MB  
  2. from tables  
  3. where table_schema='passport_v2' and table_name='tb_user_info'

--   2128.94MB   285.00MB 

 

責任編輯:龐桂玉 來源: Java知音
相關推薦

2010-10-27 16:33:39

Oracle查看表空間

2011-04-13 09:31:50

Oracle

2010-04-16 10:00:06

Oracle查看表空間

2010-11-16 11:17:41

Oracle表空間大小

2010-07-28 10:13:06

DB2查詢Table

2010-04-12 13:25:10

Oracle 數(shù)據(jù)庫

2010-05-26 16:29:51

MySQL查看

2010-05-12 14:26:01

MySQL查看表結構

2011-07-18 15:59:17

MySQL數(shù)據(jù)庫

2010-04-07 11:39:16

Oracle常用

2010-08-18 09:18:10

DB2求剩余數(shù)據(jù)庫空間

2016-01-13 09:15:48

Java對象占空間

2015-09-30 14:38:19

系統(tǒng)磁盤空間Windows 10

2022-04-01 10:37:45

戴爾

2009-11-24 17:20:48

Oracle查看用戶表

2012-05-02 14:22:55

端口占用

2010-11-03 15:41:58

DB2重命名表

2010-04-20 14:17:21

Unix操作系統(tǒng)

2010-11-03 11:26:39

DB2表空間

2024-01-24 16:31:34

數(shù)據(jù)中心虛擬化
點贊
收藏

51CTO技術棧公眾號