MySQL數(shù)據(jù)庫(kù)如何查看表占用空間大小
前言
在mysql中有一個(gè)默認(rèn)的數(shù)據(jù)表information_schema,information_schema這張數(shù)據(jù)表保存了MySQL服務(wù)器所有數(shù)據(jù)庫(kù)的信息。如數(shù)據(jù)庫(kù)名,數(shù)據(jù)庫(kù)的表,表欄的數(shù)據(jù)類(lèi)型與訪(fǎng)問(wèn)權(quán)限等。再簡(jiǎn)單點(diǎn),這臺(tái)MySQL服務(wù)器上,到底有哪些數(shù)據(jù)庫(kù)、各個(gè)數(shù)據(jù)庫(kù)有哪些表,每張表的字段類(lèi)型是什么,各個(gè)數(shù)據(jù)庫(kù)要什么權(quán)限才能訪(fǎng)問(wèn),等等信息都保存在information_schema表里面,所以請(qǐng)勿刪改此表。
1、切換數(shù)據(jù)庫(kù)
use information_schema;
2、查看所有數(shù)據(jù)庫(kù)容量大小
select table_schema as '數(shù)據(jù)庫(kù)', 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ù)庫(kù)使用大小
short_video庫(kù)名 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ù)庫(kù)容量大小
select table_schema as '數(shù)據(jù)庫(kù)', 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ù)庫(kù)各表容量大小
select table_schema as '數(shù)據(jù)庫(kù)', 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ù)庫(kù)容量大小
select table_schema as '數(shù)據(jù)庫(kù)', 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ù)庫(kù)各表容量大小
select table_schema as '數(shù)據(jù)庫(kù)', 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ù)庫(kù)如何查看表占用空間大小的文章就介紹到這了,更多相關(guān)MySQL查看表占用空間大小內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
explain執(zhí)行計(jì)劃需要關(guān)注的幾個(gè)關(guān)鍵字段詳細(xì)解釋
這篇文章主要介紹了explain執(zhí)行計(jì)劃需要關(guān)注的幾個(gè)關(guān)鍵字段的相關(guān)資料,EXPLAIN是MySQL性能優(yōu)化的關(guān)鍵工具,它提供了查詢(xún)執(zhí)行計(jì)劃的詳細(xì)信息,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2025-02-02
windows下安裝mysql8.0.18的教程(社區(qū)版)
本文章簡(jiǎn)單介紹一下mysql在windows下的安裝方式,主要介紹了mysql社區(qū)版8.0.18版本,本文給大家介紹的非常詳細(xì),需要的朋友參考下吧2020-01-01
MySQL數(shù)據(jù)庫(kù)自動(dòng)補(bǔ)全命令的三種方法
這篇文章主要介紹了MySQL數(shù)據(jù)庫(kù)自動(dòng)補(bǔ)全命令的三種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02
MySQL索引的優(yōu)化之LIKE模糊查詢(xún)功能實(shí)現(xiàn)
這篇文章主要介紹了MySQL索引的優(yōu)化之LIKE模糊查詢(xún)功能實(shí)現(xiàn),本文通過(guò)示例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧2025-04-04
MySQL 備份失敗的問(wèn)題:undo log 清理耗時(shí)10 小時(shí)的問(wèn)題解決
本文將結(jié)合實(shí)際案例,剖析MySQL 8.0.18 環(huán)境下,因undo log清理耗時(shí)過(guò)長(zhǎng)導(dǎo)致全備失敗的故障成因與解決路徑,并探討智能工具在數(shù)據(jù)庫(kù)故障診斷中的應(yīng)用價(jià)值,感興趣的朋友一起看看吧2025-06-06
mysql8.0.11數(shù)據(jù)目錄遷移的實(shí)現(xiàn)
這篇文章主要介紹了mysql8.0.11數(shù)據(jù)目錄遷移的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02

