一、information_schema數(shù)據(jù)庫
1.1、概述
????????information_schema數(shù)據(jù)庫是MySQL出廠默認帶的一個數(shù)據(jù)庫,不管我們是在Linux中安裝MySQL還是在Windows中安裝MySQL,安裝好后都會有一個數(shù)據(jù)庫information_schema,這個庫中存放了其他庫的所有信息。
1.2、關(guān)鍵表
schemata表:這個表里面主要是存儲在mysql中的所有的數(shù)據(jù)庫的信息。
tables表:這個表里存儲了所有數(shù)據(jù)庫中的表的信息,包括每個表有多少個列等信息。
columns表:這個表存儲了所有表中的表字段信息。
statistics表:存儲了表中索引的信息。
user_privileges表:存儲了用戶的權(quán)限信息。
schema_privileges表:存儲了數(shù)據(jù)庫權(quán)限。
table_privileges表:存儲了表的權(quán)限。
column_privileges表:存儲了列的權(quán)限信息。
character_sets表:存儲了mysql可以用的字符集的信息。
collations表:提供各個字符集的對照信息。
collation_character_set_applicability表:相當于collations表和character_sets表的前兩個字段的一個對比,記錄了字符集之間的對照信息。
table_constraints表:這個表主要是用于記錄表的描述存在約束的表和約束類型。
key_column_usage表:記錄具有約束的列。
routines表:記錄了存儲過程和函數(shù)的信息,不包含自定義的過程或函數(shù)信息。
views表:記錄了視圖信息,需要有show view權(quán)限。
triggers表:存儲了觸發(fā)器的信息,需要有super權(quán)限。
二、常用功能
2.1、查詢所有數(shù)據(jù)庫中所有表占據(jù)的空間
use information_schema;
select
concat(round(sum(data_length/1024/1024),2),'MB') as 'MB',
concat(round(sum(data_length/1024/1024/1024),2),'GB') as 'GB'
from tables;
?
2.2、查詢指定數(shù)據(jù)庫占據(jù)的空間
select
concat(round(sum(data_length/1024/1024),2),'MB') as 'MB',
concat(round(sum(data_length/1024/1024/1024),2),'GB') as 'GB'
from tables
where table_schema = 'vhr';
2.3、查詢指定數(shù)據(jù)庫的指定表占據(jù)的空間
select
concat(round(sum(data_length/1024),2),'KB') as 'KB',
concat(round(sum(data_length/1024/1024),2),'MB') as 'MB',
concat(round(sum(data_length/1024/1024/1024),2),'GB') as 'GB'
from tables
where table_schema = 'vhr'
and table_name = 'user';
2.4、查詢指定數(shù)據(jù)庫的指定表的索引占據(jù)的空間
2.4.1、當前數(shù)據(jù)庫中的表
2.4.2、user表中的索引信息
文章來源:http://www.zghlxwxcb.cn/news/detail-789871.html
2.4.3、user表中索引所占空間大小
文章來源地址http://www.zghlxwxcb.cn/news/detail-789871.html
2.5、參考
https://blog.csdn.net/u011334621/article/details/53066818
到了這里,關(guān)于系列十三、查詢數(shù)據(jù)庫中某個庫、表、索引等所占空間的大小的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!