Mysql查询库、表存储量(Size)
Mysql查詢庫、表存儲量(Size)
1、要查詢表所占的容量,就是把表的數據和索引加起來就可以了。
SELECT SUM(DATA_LENGTH) + SUM(INDEX_LENGTH) FROM information_schema.tables WHERE table_schema='table_name';
2、查詢所有的數據大小
SELECT CONCAT(ROUND(SUM(DATA_LENGTH/1024/1024), 2), 'M') FROM tables;
3、查詢某個表的數據
SELECT CONCAT(ROUND(SUM(DATA_LENGTH/1024/1024),2),'M') FROM tables WHERE table_schema='database_name' AND table_name='table_name';
----- 注:獲取結果是字節單位,轉換為M單位。
mysql中information_schema數據庫,存儲數據庫元數據,包括數據庫信息、數據庫中表的信息等。
schemata表:這個表里面主要是存儲在mysql中的所有的數據庫的信息
tables表:這個表里存儲了所有數據庫中的表的信息,包括每個表有多少個列等信息。
columns表:這個表存儲了所有表中的表字段信息。
statistics表:存儲了表中索引的信息。
user_privileges表:存儲了用戶的權限信息。
schema_privileges表:存儲了數據庫權限。
table_privileges表:存儲了表的權限。
column_privileges表:存儲了列的權限信息。
character_sets表:存儲了mysql可以用的字符集的信息。
collations表:提供各個字符集的對照信息。
collation_character_set_applicability表:相當于collations表和character_sets表的前兩個字段的一個對比,記錄了字符集之間的對照信息。
table_constraints表:這個表主要是用于記錄表的描述存在約束的表和約束類型。
key_column_usage表:記錄具有約束的列。
routines表:記錄了存儲過程和函數的信息,不包含自定義的過程或函數信息。
views表:記錄了視圖信息,需要有show view權限。
triggers表:存儲了觸發器的信息,需要有super權限。
1.查看所有數據庫容量大小
select table_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.tables group by table_schema order by sum(data_length) desc, sum(index_length) desc;
2.查看所有數據庫各表容量大小
select table_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.tables order by data_length desc, index_length desc;
3.查看指定數據庫容量大小
select table_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.tables where table_schema='mysql';
4.查看指定數據庫各表容量大小
select table_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.tables where table_schema='mysql' order by data_length desc, index_length desc;
總結
以上是生活随笔為你收集整理的Mysql查询库、表存储量(Size)的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 《精灵宝可梦Lets go》鬼斯怎么捕捉
- 下一篇: SAP Spartacus 3.0 的一
