mysql 查看表大小的方法實(shí)踐
1.查看所有數(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;
2.查看所有數(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;
3.查看指定數(shù)據(jù)庫(kù)容量大小
例:查看mysql庫(kù)容量大?。捍a如下:
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='mysql';
4.查看指定數(shù)據(jù)庫(kù)各表容量大小*
例:查看mysql庫(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='mysql' order by data_length desc, index_length desc;
PS:查看MySql數(shù)據(jù)空間使用情況:
information_schema是MySQL的系統(tǒng)數(shù)據(jù)庫(kù),information_schema里的tables表存放了整個(gè)數(shù)據(jù)庫(kù)各個(gè)表的使用情況。
可以使用sql來(lái)統(tǒng)計(jì)出數(shù)據(jù)庫(kù)的空間使用情況,相關(guān)字段:
- table_schema:數(shù)據(jù)庫(kù)名
- table_name:表名
- table_rows:記錄數(shù)
- data_length:數(shù)據(jù)大小
- index_length:索引大小
使用空間
1、統(tǒng)計(jì)表使用空間
select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables where table_schema='mydb' and table_name='mytable';
| data |
| 0.02mb |
1 row in set (0.00 sec)
2、統(tǒng)計(jì)數(shù)據(jù)庫(kù)使用空間
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='mydb';
| data |
| 6.64MB |
1 row in set (0.00 sec)
3、統(tǒng)計(jì)所有數(shù)據(jù)使用空間
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;
| data |
| 6.64MB |
1 row in set (0.01 sec)
到此這篇關(guān)于mysql 查看表大小的方法實(shí)踐的文章就介紹到這了,更多相關(guān)mysql 查看表大小內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
MYSQL必知必會(huì)讀書筆記第四章之檢索數(shù)據(jù)
MySQL是一種開(kāi)放源代碼的關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng)(RDBMS)。接下來(lái)通過(guò)本文給大家介紹MYSQL必知必會(huì)讀書筆記第四章之檢索數(shù)據(jù),感興趣的朋友一起學(xué)習(xí)吧2016-05-05一臺(tái)服務(wù)器部署兩個(gè)獨(dú)立的mysql數(shù)據(jù)庫(kù)操作實(shí)例
這篇文章主要給大家介紹了關(guān)于一臺(tái)服務(wù)器部署兩個(gè)獨(dú)立的mysql數(shù)據(jù)庫(kù)的相關(guān)資料,同一臺(tái)服務(wù)器裝兩個(gè)數(shù)據(jù)庫(kù),可以通過(guò)虛擬化技術(shù)實(shí)現(xiàn),文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-03-03高并發(fā)狀態(tài)下Replace Into造成的死鎖問(wèn)題解決
本文主要介紹了高并發(fā)狀態(tài)下Replace Into造成的死鎖問(wèn)題解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01解決net start mysql--服務(wù)無(wú)法啟動(dòng) 服務(wù)沒(méi)有報(bào)告任何錯(cuò)誤問(wèn)題
這篇文章主要介紹了解決net start mysql--服務(wù)無(wú)法啟動(dòng) 服務(wù)沒(méi)有報(bào)告任何錯(cuò)誤問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12MySQL系列多表連接查詢92及99語(yǔ)法示例詳解教程
這篇文章主要為大家介紹了MySQL系列多表連接查詢92及99語(yǔ)法示例詳解教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2021-10-10