mysql 查看表大小的方法實踐
1.查看所有數(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;
2.查看所有數(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;
3.查看指定數(shù)據(jù)庫容量大小
例:查看mysql庫容量大?。捍a如下:
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='mysql';
4.查看指定數(shù)據(jù)庫各表容量大小*
例:查看mysql庫各表容量大小
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='mysql' order by data_length desc, index_length desc;
PS:查看MySql數(shù)據(jù)空間使用情況:
information_schema是MySQL的系統(tǒng)數(shù)據(jù)庫,information_schema里的tables表存放了整個數(shù)據(jù)庫各個表的使用情況。
可以使用sql來統(tǒng)計出數(shù)據(jù)庫的空間使用情況,相關字段:
- table_schema:數(shù)據(jù)庫名
- table_name:表名
- table_rows:記錄數(shù)
- data_length:數(shù)據(jù)大小
- index_length:索引大小
使用空間
1、統(tǒng)計表使用空間
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)計數(shù)據(jù)庫使用空間
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)計所有數(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)
到此這篇關于mysql 查看表大小的方法實踐的文章就介紹到這了,更多相關mysql 查看表大小內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
MYSQL必知必會讀書筆記第四章之檢索數(shù)據(jù)
MySQL是一種開放源代碼的關系型數(shù)據(jù)庫管理系統(tǒng)(RDBMS)。接下來通過本文給大家介紹MYSQL必知必會讀書筆記第四章之檢索數(shù)據(jù),感興趣的朋友一起學習吧2016-05-05一臺服務器部署兩個獨立的mysql數(shù)據(jù)庫操作實例
這篇文章主要給大家介紹了關于一臺服務器部署兩個獨立的mysql數(shù)據(jù)庫的相關資料,同一臺服務器裝兩個數(shù)據(jù)庫,可以通過虛擬化技術實現(xiàn),文中通過代碼介紹的非常詳細,需要的朋友可以參考下2024-03-03高并發(fā)狀態(tài)下Replace Into造成的死鎖問題解決
本文主要介紹了高并發(fā)狀態(tài)下Replace Into造成的死鎖問題解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-01-01解決net start mysql--服務無法啟動 服務沒有報告任何錯誤問題
這篇文章主要介紹了解決net start mysql--服務無法啟動 服務沒有報告任何錯誤問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12