1.查看所有数据库容量大小 select table_schema as '数据库', sum(table_rows) as '记录数', sum(truncate(dat
1.查看所有数据库容量大小
select
table_schema as '数据库',
sum(table_rows) as '记录数',
sum(truncate(data_length/1024/1024, 2)) as '数据容量(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.查看所有数据库各表容量大小
select
table_schema as '数据库',
table_name as '表名',
table_rows as '记录数',
truncate(data_length/1024/1024, 2) as '数据容量(MB)',
truncate(index_length/1024/1024, 2) as '索引容量(MB)'
from information_schema.tables
order by data_length desc, index_length desc;
3.查看指定数据库容量大小
例:查看Mysql库容量大小:代码如下:
select
table_schema as '数据库',
sum(table_rows) as '记录数',
sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',
sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'
from information_schema.tables
where table_schema='mysql';
4.查看指定数据库各表容量大小*
例:查看mysql库各表容量大小
select
table_schema as '数据库',
table_name as '表名',
table_rows as '记录数',
truncate(data_length/1024/1024, 2) as '数据容量(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;
information_schema是MySQL的系统数据库,information_schema里的tables表存放了整个数据库各个表的使用情况。
可以使用sql来统计出数据库的空间使用情况,相关字段:
1、统计表使用空间
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、统计数据库使用空间
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、统计所有数据使用空间
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 查看表大小内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: mysql查看表大小的方法实践
本文链接: https://www.lsjlt.com/news/176879.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-16
2024-05-16
2024-05-16
2024-05-15
2024-05-15
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0