mysql 查看表大小的方法实践
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;
PS:查看MySql数据空间使用情况:
information_schema是MySQL的系统数据库,information_schema里的tables表存放了整个数据库各个表的使用情况。
可以使用sql来统计出数据库的空间使用情况,相关字段:
- table_schema:数据库名
- table_name:表名
- table_rows:记录数
- data_length:数据大小
- index_length:索引大小
使用空间
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 查看表大小内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
MySQL索引查询limit offset及排序order by用法
这篇文章主要介绍了MySQL限制数据返回条数limit offset及排序order by用法,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-05-05MySQL into_Mysql中replace与replace into用法案例详解
这篇文章主要介绍了MySQL into_Mysql中replace与replace into用法案例详解,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下2021-09-09MySQL 5.6 中的 TIMESTAMP 和 explicit_defaults_for_timestamp 参数
这篇文章主要介绍了MySQL 5.6 中的 TIMESTAMP 和 explicit_defaults_for_timestamp 参数,需要的朋友可以参考下2015-08-08MySQL中SHOW DATABASES语句查看或显示数据库
在MySQL中,可使用SHOW DATABASES语句来查看或显示当前用户权限范围以内的数据库,下面就来介绍一下如何使用,具有一定的参考价值,感兴趣的可以了解一下2024-02-02
最新评论