文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

17.11.5 使用 TRUNCATE TABLE 回收磁盘空间17.11.5 Reclaiming Disk Space with TRUNCATE TABLE

在截断一个InnoDB表时,为了回收操作系统磁盘空间,该表必须存储在它自己的.ibd文件。要将表存储在自己的.ibd文件中,innodb_file_per_table必须在创建表时启用。此外,foreign key被截断表与其他表之间TRUNCATE TABLE外键To reclaim operating system disk space when truncating an InnoDB table, the table must be stored in its own .ibd file. For a table to be stored in its own .ibd file, innodb_file_per_table must enabled when the table is created. Additionally, there cannot be a foreign key constraint between the table being truncated and other tables, otherwise the TRUNCATE TABLE operation fails. A foreign key constraint between two columns in the same table, however, is permitted.

当一个表被截断时,它会被删除并在一个新的 .ibd 文件中重新创建,释放的空间会返回操作系统。这与截断存储在 InnoDB 系统表空间 中的 InnoDB 表(当 innodb_file_per_table=OFF 时创建的表)以及存储在共享 通用表空间 中的表不同,在这些情况下,截断表后只有 InnoDB 可以使用释放的空间。When a table is truncated, it is dropped and re-created in a new .ibd file, and the freed space is returned to the operating system. This is in contrast to truncating InnoDB tables that are stored within the InnoDB system tablespace (tables created when innodb_file_per_table=OFF) and tables stored in shared general tablespaces, where only InnoDB can use the freed space after the table is truncated.

截断表并将磁盘空间返回给操作系统的能力也意味着物理备份可以更小。在系统表空间中截断表(当innodb_file_per_table=OFF时创建的表)或在通用表空间中截断表,会在表空间中留下未使用的空间块。The ability to truncate tables and return disk space to the operating system also means that physical backups can be smaller. Truncating tables that are stored in the system tablespace (tables created when innodb_file_per_table=OFF) or in a general tablespace leaves blocks of unused space in the tablespace.