查询数据库所占空间

1

2

3

select concat(round(sum(data_length/1024/1024),2),'MB') as data from 

information_schema.tables 

where table_schema='dbName';

查询表所占空间

1

2

select concat(round(sum(data_length/1024/1024),2),'MB'as data from information_schema.tables 

where table_schema='dbName' and table_name='tableName';

查询数据库所有表所占空间

1

2

select concat(round(sum(data_length/1024/1024),2),'MB'as data,table_name from information_schema.tables 

where table_schema='dbName' GROUP BY table_name ORDER BY data desc;

查看所有数据库容量大小

1

2

3

4

5

6

7

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) descsum(index_length) desc;

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

1

2

3

4

5

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;

查看指定数据库容量大小

1

2

3

4

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='dbName';

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

1

2

3

4

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='dbName'

order by data_length desc, index_length desc;

mysql数据库整理碎片方法:

查看碎片方法

1

2

3

select table_schema db, table_name, data_free, engine     

from information_schema.tables 

where table_schema not in ('information_schema''mysql')  and data_free > 0;

清除表碎片

1

2

3

4

方法1 alter table 表名 engine=InnoDB

alter table tableName engine=InnoDB;

#方法2 optimize table 表名

optimize table tableName;

MySQL数据库查看表占用空间大小及碎片整理相关推荐

  1. MySQL之查看表占用空间大小

    文章目录 information_schema 查看表大小 information_schema 在mysql中有一个默认的数据库information_schema,information_sche ...

  2. MySQL查看表占用空间大小

    需求:我们在选购服务器硬盘时,通常需要先估算一下数据量.比如我们现在做的项目,百万级用户,然后在现有的数据结构中插入一万条数据,然后根据相应的需求去计算出实际生产中的数据量. 前言:在mysql中有一 ...

  3. mysql如何查看表的大小_mysql 如何查看表的大小

    mysql 查看表的大小方法:1.查看所有数据库各表容量大小,代码为[truncate(data_length/1024/1024, 2) as '数据容量(MB)']:2.查看指定数据库各表容量大小 ...

  4. Hive下查看表占用空间大小的方法

    一.Hive下查看数据表信息的方法 方法1:查看表的字段信息 desc table_name; 方法2:查看表的字段信息及元数据存储路径 desc extended table_name; 方法3:查 ...

  5. php检测表大小,查询mysql数据库、表的大小

    一.关于mysql表数据大小 mysql存储数据文件一般使用表空间存储 : 当mysql使用innodb存储引擎的时候,mysql使用表存储数据分为共享表空间和独享表空间两种方式 .共享表空间:Inn ...

  6. DB2 查看表占用空间大小

    1.查看数据库页大小 db2 get db cfg 2.收集表状态信息 db2 runstats on table schema.table_name 3.查询数据表占用页的数量 select tab ...

  7. MYSQL数据库表大小计算,计算mysql数据库数据表的大小,不精确,只是大略的数据...

    SHOW TABLE STATUS dbname 返回数组: Name: xxx (表名) Engine: MyISAM (表引擎) Version: 10 (版本) Row_format: Dyna ...

  8. MySQL 查看数据库和表空间大小及碎片处理

    1. 查看所有数据库空间大小 SELECT table_schema as '数据库',sum(table_rows) as '记录数',sum(truncate(data_length/1024/1 ...

  9. MySQL查看表占用空间大小(转)

    //先进去MySQL自带管理库:information_schema //自己的数据库:dbwww58com_kuchecarlib //自己的表:t_carmodelparamvalue mysql ...

最新文章

  1. [转]阿里巴巴集团去IOE运动的思考与总结
  2. 工程制图 (装配图)
  3. C#学习笔记(集合)
  4. asp.net写入日志到文本文件
  5. css3中的BFC,IFC,GFC和FFC(转载)
  6. quartz.net隔一天执行一次_你知多少年的轮回,中秋和国庆在同一天吗?喜相逢必备“蟹”逅礼...
  7. html 复选框name值,HTML(5)表单元素以及对各个表单元素的name、value属性的理解
  8. Spring : BeanDefinition
  9. Windows Phone开发之路(14) 加载位图
  10. 为什么使用getrequestdispatcher跳转出现404_网站出现404错误时的处理方法
  11. iText制作表格比较好的文章
  12. nginx的学习笔记,第四记。
  13. wap网站制作教程,Github标星5.3K
  14. 浮动时间怎么计算_自由浮动时间 VS 总浮动时间
  15. python-字符串的操作方法_format_列表的操作
  16. 林燕妮: 一见杨过误终生
  17. 监控 - Prometheus监控
  18. OSChina 周五乱弹 —— 生命诚可贵,改 BUG 价更高?
  19. 系统集成项目管理工程师英语题翻译
  20. 大数据处理基本思想——分治法

热门文章

  1. Python将文件映射到内存使用mmap.mmap()函数
  2. java笔试题String字符串单词逆序how are you变成are you how
  3. 架构之重构的12条军规!送给自己的礼物~
  4. 为什么一定要捯饬个人网站
  5. 实例028:递归求等差数列
  6. 戴尔R730服务器设置管理IP(iDRAC)和安装系统
  7. 2022年十大新晋加密独角兽
  8. 安卓开机画面_一张壁纸就会让你的安卓手机死机?谨慎尝试!(附解决办法)...
  9. php sequelize,Sequelize中用group by进行分组聚合查询
  10. 基础_ _返回键back