mysql 查看表大小的方法實(shí)踐
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)計(jì)出數(shù)據(jù)庫的空間使用情況,相關(guān)字段:
- table_schema:數(shù)據(jù)庫名
- 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ù)庫使用空間
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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
mysql中l(wèi)imit查詢踩坑實(shí)戰(zhàn)記錄
在MySQL中我們常常用order by來進(jìn)行排序,使用limit來進(jìn)行分頁,下面這篇文章主要給大家介紹了關(guān)于mysql中l(wèi)imit查詢踩坑的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-03-03
MySQL中ON DUPLICATE KEY UPDATE語句的使用
INSERT INTO ... ON DUPLICATE KEY UPDATE?是一個強(qiáng)大的SQL語句,它結(jié)合了插入新記錄和更新已存在記錄的功能于一體,本文就來介紹一下MySQL中ON DUPLICATE KEY UPDATE語句的使用,感興趣的可以了解一下2024-08-08
MySQL數(shù)據(jù)庫事務(wù)原理及應(yīng)用
MySQL數(shù)據(jù)庫事務(wù)是指一組數(shù)據(jù)庫操作,要么全部執(zhí)行成功,要么全部回滾。事務(wù)可以確保數(shù)據(jù)的一致性和完整性,避免了多個用戶同時對同一數(shù)據(jù)進(jìn)行修改所帶來的問題。MySQL通過事務(wù)日志記錄事務(wù)的操作,支持事務(wù)的回滾和提交等操作2023-04-04
通過實(shí)例分析MySQL中的四種事務(wù)隔離級別
SQL標(biāo)準(zhǔn)定義了4種隔離級別,包括了一些具體規(guī)則,用來限定事務(wù)內(nèi)外的哪些改變是可見的,哪些是不可見的。下面這篇文章通過實(shí)例詳細(xì)的給大家分析了關(guān)于MySQL中的四種事務(wù)隔離級別的相關(guān)資料,需要的朋友可以參考下。2017-08-08

