您正在使用 IPV4 [54.227.104.229] 访问本站,您本次已经查看了 1 页
用户名: 密 码: 验证码:     用QQ登录本站
首页 软件 编程 笑话 知识 公告 台风 日历 计算器
悟空收录网       [公益]保护绿色环境,构建和谐社会      

【腾讯云】 爆款2核2G3M云服务器首年 61元,叠加红包再享折上折      
[公益] 地球是我家,绿化靠大家      
2024年 清明节 007
2024年 劳动节 034
2025年 元 旦 279
2025年 春 节 307
 
您现在的位置:首页 >> 数据库 >> 内容
本类新增
本类热门
mysql 查看表大小的方法实践
内容摘要: 1.查看所有数据库容量大小selecttable_schemaas'数据库',sum(table_rows)as'记录数',sum(truncate(data_length/1024/1024,2))as'数据容量(MB)',sum(truncate(index_length/1024/1024,2))as'索引容量(MB)'frominformation_......
1.查看所有数据库容量大小

select

table_schemaas'数据库',

sum(table_rows)as'记录数',

sum(truncate(data_length/1024/1024,2))as'数据容量(MB)',

sum(truncate(index_length/1024/1024,2))as'索引容量(MB)'

frominformation_schema.tables

groupbytable_schema

orderbysum(data_length)desc,sum(index_length)desc;

2.查看所有数据库各表容量大小

select

table_schemaas'数据库',

table_nameas'表名',

table_rowsas'记录数',

truncate(data_length/1024/1024,2)as'数据容量(MB)',

truncate(index_length/1024/1024,2)as'索引容量(MB)'

frominformation_schema.tables

orderbydata_lengthdesc,index_lengthdesc;

3.查看指定数据库容量大小

例:查看mysql库容量大小:代码如下:

select

table_schemaas'数据库',

sum(table_rows)as'记录数',

sum(truncate(data_length/1024/1024,2))as'数据容量(MB)',

sum(truncate(index_length/1024/1024,2))as'索引容量(MB)'

frominformation_schema.tables

wheretable_schema='mysql';

4.查看指定数据库各表容量大小*

例:查看mysql库各表容量大小

select

table_schemaas'数据库',

table_nameas'表名',

table_rowsas'记录数',

truncate(data_length/1024/1024,2)as'数据容量(MB)',

truncate(index_length/1024/1024,2)as'索引容量(MB)'

frominformation_schema.tables

wheretable_schema='mysql'

orderbydata_lengthdesc,index_lengthdesc;

PS:查看MySql数据空间使用情况:

information_schema是MySQL的系统数据库,information_schema里的tables表存放了整个数据库各个表的使用情况。

可以使用sql来统计出数据库的空间使用情况,相关字段:

table_schema:数据库名

table_name:表名

table_rows:记录数

data_length:数据大小

index_length:索引大小

使用空间

1、统计表使用空间

selectconcat(round(sum(data_length/1024/1024),2),'mb')asdatafromtableswheretable_schema='mydb'andtable_name='mytable';

|data|

|0.02mb|

1rowinset(0.00sec)

2、统计数据库使用空间

selectconcat(round(sum(data_length/1024/1024),2),'MB')asdatafromtableswheretable_schema='mydb';

|data|

|6.64MB|

1rowinset(0.00sec)

3、统计所有数据使用空间

selectconcat(round(sum(data_length/1024/1024),2),'MB')asdatafromtables;

|data|

|6.64MB|

1rowinset(0.01sec)

版权声明:本内容来源于网络,如有侵犯您的版权,请联系站长,本站收到您的信息后将及时处理。
上一篇:MySql日期查询数据的实现

 

下一篇:解决Access出现Microsoft JET Databa

发布日期:2023/1/7
手机扫二维码直达本页
发布时间:11:30:57
点  击:11
录  入:壹家怡园
相关文章
Baidu
YiJiaCMS 7.3.8 build231228(MSSQL) 闽ICP备05000814号-1
本空间由腾讯云(轻量应用服务器)提供,Cloudflare提供加速防护
运行时间载入中.....