MySQL 的 information_schema 数据库记录了数据库的元数据,包括数据库名、表名、列的数据类型、访问权限等。但是 information_schema 中的表实际上是视图,而不是基本表。
通过 information_schema 可以查询各个库、表的容量大小。
主要代码如下:
1、查看数据库的大小
select concat(round(sum(data_length/1024/1024),2),’MB’) as data from tables where table_schema=’DB_Name’ ;
2、查看表的大小
select concat(round(sum(data_length/1024/1024),2),’MB’) as data from tables where table_schema=’DB_Name’ and table_name=’Table_Name’;
查看 mysql 库的大小。table_schema='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';
查看 mysql 库中各个表的大小。table_schema='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;
本文来源:程序之心,转载请注明出处!
作为经典的软件需求工程畅销书,经由需求社区两大知名领袖结对全面修订和更新,覆盖新的主题、实例和指南,全方位讨论软件项目所涉及的所有需求开发和管理活动,介绍当下的所有实践。书中描述实用性强的、高效的、经过实际检验的端到端需求工程管理技术,通过丰富的实例来演示如何利用实践来减少订单变更,提高客户满意度,减少开发成本。
最新内容
© 2016 - 2024 chengxuzhixin.com All Rights Reserved.