0

我正在使用具有单个文件配置(在 /var 中)的 InnoDB 数据库,所以没有 innodb_file_per_table。

在 MySql 工作台中,当我查询数据库已用空间时,使用此查询

SELECT table_schema "Database", sum( data_length + index_length ) / 1024 / 1024 "Data     Base Size in MB" 
FROM information_schema.TABLES GROUP BY table_schema;

它说我有 47 GB 的数据。但是 ibdata1 的大小是 99 GB...

我知道 ibdata1 包含除表数据之外的许多其他内容,例如表索引、MVCC(多版本并发控制)数据和表元数据

所以我的问题是:据说 52 GB 的 ibdata1 是 medatada 和一堆其他东西,这正常吗?通常,ibdata1 文件应该包含多少表数据旁边的数据?

4

2 回答 2

2

不,拥有这么多元数据是不正常的。如果您不使用innodb_file_per_table.

当您的数据库增长时,您的 ibdata 文件会增长,但它永远不会真正缩小。

因此,例如,如果您曾经有 130 GB 的数据并删除了其中的一堆,那么清除数据后 ibdata 文件仍将是 130 GB。它只会有一堆“可用空间”,然后它将用于后续插入。

至于缩小文件,除了清除数据库并恢复它之外,您实际上无能为力。这个答案有一些关于如何做到这一点的很好的说明。

Howto:清理 mysql InnoDB 存储引擎?

您可能还需要考虑将innodb_file_per_table其用作从表中删除数据,然后优化该表实际上会缩小各个表文件的大小

于 2013-01-07T15:36:55.970 回答
2

在 ibdata1 中有一堆“额外”空间有几个原因,但最可能的情况是:

  • You have deleted large amounts of data in the past. When you delete rows or drop tables, although free space will be made available in the file, the file itself will never shrink.
  • You may have an excessive amount of undo log space (or have at some point in the past). Undo logs are kept during DELETE and UPDATE operations, and for very long-running operations touching many rows can grow quite large. Again, if the file is expanded to hold this data it will never shrink.

As previously mentioned using innodb_file_per_table can help with this if you expect to regularly drop tables and want to get the disk space back. My blog post The basics of InnoDB space file layout may help you understand what is included in the ibdata1 file.

于 2013-01-07T21:17:17.577 回答