简体   繁体   English

为什么MySQL数据库中没有可用空间?

[英]Why is there no free space in MySQL database?

Recently, I checked the SQL databases I'm using in phpMyAdmin (with WAMP), and they all report no free space. 最近,我检查了我在phpMyAdmin(使用WAMP)中使用的SQL数据库,并且它们都报告没有可用空间。 This was not true before, and I'm not sure what caused it to change. 之前不是这样,我不确定是什么导致它改变。 The lack of free space is making calls to the databases very, very slow. 缺少可用空间使得对数据库的调用非常非常缓慢。 I've reinstalled WAMP, created a new user for phpMyAdmin, and reimported the databases into the new user, but to no avail. 我重新安装了WAMP,为phpMyAdmin创建了一个新用户,并将数据库重新导入新用户,但无济于事。

Here is the query I used to check for space and the result: 这是我用来检查空间和结果的查询:

SELECT table_schema "beek", SUM( data_length + index_length ) /1024 / 1024 "Data Base Size in MB", SUM( data_free ) /1024 /1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema
LIMIT 0 , 30
beek
Data Base Size in MB
Free Space in MB

-------------------------------------------
beek

Data Base Size in MB 4.11813927

Free Space in MB 0.00000000

-----------------------------------------
information_schema

Data Base Size in MB 0.00976563

Free Space in MB 0.00000000

---------------------------------------
mysql

Data Base Size in MB 0.76406479

Free Space in MB 0.00000000

-------------------------------------
performance_schema

Data Base Size in MB 0.00000000

Free Space in MB 0.00000000

--------------------------------------------

Does anyone know why all of the extra space in these databases has disappeared? 有谁知道为什么这些数据库中的所有额外空间都消失了?

"Free space" for InnoDB tables is reported as the size of extents that have no data. InnoDB表的“可用空间”报告为没有数据的扩展区的大小。

When a tablespace file grows physically, it grows in a big chunks of pages, called extents. 当表空间文件在物理上增长时,它会在一大块页面中增长,称为范围。 Then you gradually INSERT data to fill the extent. 然后逐渐插入数据以填充范围。

You could have previously queries the information_schema when you had just allocated new extents, but before you inserted data. 您可以在刚刚分配新扩展区时,但在插入数据之前查询information_schema。 Then as you insert data, it uses some space in the extent and it's no longer unoccupied (even if it's only partially filled). 然后在插入数据时,它会在范围内使用一些空间,并且它不再被占用(即使它只是部分填充)。

Extents in the middle of the tablespace file can also be emptied when you do a lot of DELETEs. 当您执行大量DELETE时,也可以清空表空间文件中间的区域。 But then that free space is re-used by later INSERTs. 但后来INSERT重新使用了这个空闲空间。

Either way, having zero unoccupied extents is normal, and it's not a problem. 无论哪种方式,具有零未占用的范围是正常的,并且它不是问题。 If the file needs to grow physically, InnoDB can do that. 如果文件需要物理增长,InnoDB可以做到这一点。

For more details, see: 有关详细信息,请参阅:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM