MySQL數(shù)據(jù)庫如何查看表占用空間大小
前言
在mysql中有一個默認的數(shù)據(jù)表information_schema,information_schema這張數(shù)據(jù)表保存了MySQL服務(wù)器所有數(shù)據(jù)庫的信息。如數(shù)據(jù)庫名,數(shù)據(jù)庫的表,表欄的數(shù)據(jù)類型與訪問權(quán)限等。再簡單點,這臺MySQL服務(wù)器上,到底有哪些數(shù)據(jù)庫、各個數(shù)據(jù)庫有哪些表,每張表的字段類型是什么,各個數(shù)據(jù)庫要什么權(quán)限才能訪問,等等信息都保存在information_schema表里面,所以請勿刪改此表。
1、切換數(shù)據(jù)庫
use information_schema;
2、查看所有數(shù)據(jù)庫容量大小
select table_schema as '數(shù)據(jù)庫', sum(table_rows) as '記錄數(shù)', sum(truncate(data_length/1024/1024, 2)) as '數(shù)據(jù)容量(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;
3、查看指定數(shù)據(jù)庫使用大小
short_video庫名 video_info 表名
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='short_video';
4、查看表使用大小
video_info 表名
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='short_video' and table_name='video_info';
5、查看所有數(shù)據(jù)庫容量大小
select table_schema as '數(shù)據(jù)庫', sum(table_rows) as '記錄數(shù)', sum(truncate(data_length/1024/1024, 2)) as '數(shù)據(jù)容量(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;
6、查看所有數(shù)據(jù)庫各表容量大小
select table_schema as '數(shù)據(jù)庫', table_name as '表名', table_rows as '記錄數(shù)', truncate(data_length/1024/1024, 2) as '數(shù)據(jù)容量(MB)', truncate(index_length/1024/1024, 2) as '索引容量(MB)' from information_schema.tables order by data_length desc, index_length desc;
7、查看指定數(shù)據(jù)庫容量大小
select table_schema as '數(shù)據(jù)庫', sum(table_rows) as '記錄數(shù)', sum(truncate(data_length/1024/1024, 2)) as '數(shù)據(jù)容量(MB)', sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)' from information_schema.tables where table_schema='short_video';
8、查看指定數(shù)據(jù)庫各表容量大小
select table_schema as '數(shù)據(jù)庫', table_name as '表名', table_rows as '記錄數(shù)', truncate(data_length/1024/1024, 2) as '數(shù)據(jù)容量(MB)', truncate(index_length/1024/1024, 2) as '索引容量(MB)' from information_schema.tables where table_schema='short_video' order by data_length desc, index_length desc;
總結(jié)
到此這篇關(guān)于MySQL數(shù)據(jù)庫如何查看表占用空間大小的文章就介紹到這了,更多相關(guān)MySQL查看表占用空間大小內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Sphinx/MySQL 協(xié)議支持與SphinxQL應(yīng)用實例
Sphinx/MySQL 協(xié)議支持與SphinxQL應(yīng)用例子,供大家學習參考2013-02-02MySQL 5.0.96 for Windows x86 32位綠色精簡版安裝教程
這篇文章主要介紹了MySQL 5.0.96 for Windows x86 32位綠色精簡版安裝教程,需要的朋友可以參考下2017-10-10mysql清空表數(shù)據(jù)的兩種方式和區(qū)別解析
這篇文章主要介紹了mysql清空表數(shù)據(jù)的兩種方式和區(qū)別,本文通過文字實例代碼相結(jié)合給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-05-05mysql使用from與join兩表查詢的區(qū)別總結(jié)
這篇文章主要給大家介紹了關(guān)于mysql使用from與join兩表查詢的區(qū)別的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2018-12-12mysql8.0.19基礎(chǔ)數(shù)據(jù)類型詳解
這篇文章主要介紹了mysql8.0.19基礎(chǔ)數(shù)據(jù)類型的相關(guān)知識,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值 ,需要的朋友可以參考下2020-03-03