MySQL 在mysql中删除数据库后回收磁盘空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5983814/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:52:06  来源:igfitidea点击:

Reclaim disk space after drop database in mysql

mysqldrop-database

提问by VenerableAgents

I've created some very large databases and have since dropped a few. I've noticed my disk space has not recovered as much as I had expected. For instance, the last database I added actually used up all of my free space and aborted, so I dropped that schema. Before this I had 12.4 GB free, now I only have 7.52 GB free.
What's going on here? How do I get my ~5 GB back?

我创建了一些非常大的数据库,后来又删除了一些。我注意到我的磁盘空间没有像我预期的那样恢复。例如,我添加的最后一个数据库实际上用完了我所有的可用空间并中止,所以我删除了该模式。在此之前,我有 12.4 GB 可用空间,现在我只有 7.52 GB 可用空间。
这里发生了什么?我如何取回我的 ~5 GB?

采纳答案by Chris Morgan

From http://dev.mysql.com/doc/refman/5.1/en/innodb-data-log-reconfiguration.html:

http://dev.mysql.com/doc/refman/5.1/en/innodb-data-log-reconfiguration.html

Currently, you cannot remove a data file from the tablespace. To decrease the size of your tablespace, use this procedure:

  1. Use mysqldump to dump all your InnoDB tables.

  2. Stop the server.

  3. Remove all the existing tablespace files, including the ibdata and ib_log files. If you want to keep a backup copy of the information, then copy all the ib* files to another location before the removing the files in your MySQL installation.

  4. Remove any .frm files for InnoDB tables.

  5. Configure a new tablespace.

  6. Restart the server.

  7. Import the dump files.

目前,您无法从表空间中删除数据文件。要减小表空间的大小,请使用以下过程:

  1. 使用 mysqldump 转储所有 InnoDB 表。

  2. 停止服务器。

  3. 删除所有现有的表空间文件,包括 ibdata 和 ib_log 文件。如果要保留信息的备份副本,请在删除 MySQL 安装中的文件之前将所有 ib* 文件复制到另一个位置。

  4. 删除 InnoDB 表的任何 .frm 文件。

  5. 配置一个新的表空间。

  6. 重新启动服务器。

  7. 导入转储文件。

Innodb creates a filesystem (the "tablespace") within the data files themselves. It never "shrinks" the data files when data is removed, since the reorganization of the data within the file could be costly (there's no guarantee that the data removed was at the end, or even contiguous). By recreating the database as described above, it makes the file as large as necessary for all the data, but no larger.

Innodb 在数据文件本身内创建一个文件系统(“表空间”)。当数据被删除时,它永远不会“收缩”数据文件,因为在文件中重新组织数据可能代价高昂(不能保证被删除的数据在最后,甚至是连续的)。通过如上所述重新创建数据库,它使文件与所有数据所需的一样大,但不会更大。