---
title: "关于MySQL 查询表数据大小的总结"
author: "wenson"
date: "2014-09-18T18:14:48Z"
tags: []
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2014-09-18T18:14:48Z"
id: 2117962
url: "https://wenson.iteye.com/blog/2117962"
---

**一：关于mysql表数据大小**

我们知道mysql存储数据文件一般使用表空间存储   
当mysql使用innodb存储引擎的时候，mysql使用表存储数据分为共享表空间和独享表空间两种方式   
·共享表空间：Innodb的所有数据保存在一个单独的表空间里面，而这个表空间可以由很多个文件组成，一个表可以跨多个文件存在。   
所以其大小限制不再是文件大小的限制，而是其自身的限制    
\--&gt;innodb官方显示表空间的最大限制为64TB   
·独享表空间：每个表的数据以一个单独的文件来存放，这个时候的单表限制，又变成文件系统的大小限制了          
在默认情况下，MySQL创建的MyISAM表允许的最大尺寸为4GB 

**二：关于show table stauts\\G;中显示内容的解释**

Data\_length: 150032---&gt;表中数据的大小   
Index\_length: 183107584---&gt;表的索引的大小   
Data\_free: 25238175744---&gt;表空间的大小   
data\_Free :如果是共享表空间 data\_free 是共享表空间的大小而非数据的大小。   
如果是独享表空间才是该表的剩余空间。   
如果表是分区存储的，data\_free 就是一个近似值而非精确值所以此时需要查询 

```
select sum(data_free) from information_schema.partitions where table_schema = 'db_name' and table_name='tab_name'; 
```

   
查询所有数据库的大小   
1:

```
use information_schema; 
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables； 
```

   
2:查询指定库大小

```
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='database_name'; 
```

   
3: 查询指定表的大小 

```
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='database_name' and table_name='table_name';
```

 

 

**三：判断mysql I/0 性能的一种方式(网络搜集供参考)**

show global status like 'innodb\_dblwr%'\\G    
如果innodb\_dblwr\_pages\_writen/innodb\_dblwr\_writes远小于64：1，说明磁盘写入压力不高            
show engine innodb status\\G 查看缓冲池的方法。    
select table\_name,data\_length+index\_length,table\_rows from tables where table\_schema='database\_name' and table\_name='table\_name';