简体   繁体   中英

MySQL tableName.Ibd file size is huge

Recently I have replicated a MySQL DB from one server to another one. Mean while I have cleared many number of rows from Master DB. So after some time replication is done properly. I verified count of data in both DB, it is same.

After that I just verified DB size in slave using below query.

SELECT table_schema "Schema_Name", Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB" FROM   information_schema.tables GROUP  BY table_schema;

By this query I got the DB's size. It is 60 GB.


My Problem

I have a file named tableName.ibd inside "ProgramData->Data->DBName" folder. This file occupies 500GB of memory.

So my question is that why this file occupies this much of size, though my DB size itself only 60GB.

Also I verified Ibdata file size inside program data. It is 1GB only.

Please help me on this. How to purge this file. What will be the impact on purging this.

The file gets fragmented when data gets deleted. If you deleted most of the records in the table it is normal that most of it would be empty.

The easiest way to 'defragment' it is by running ALTER TABLE tablename FORCE . This does a no-op alter and rebuilds the table.

A 60GB table will take a while to rebuild, so be careful about when you run it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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