1

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.

1 Answer 1

2

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.

3
  • Thanks for the answer. I dont under this line " If you deleted most of the records in the table it is normal that most of it would be empty."
    – Power Star
    Aug 23, 2017 at 15:54
  • Also one more question - I am not seeing this tablename.ibd file in master DB. I am seeing it in only slave's one.
    – Power Star
    Aug 23, 2017 at 15:59
  • There are a two reasons for this: 1. innodb_file_per_table is off - tables share data files; 2. the table is not InnoDB - in this case the file name will be different;
    – Vatev
    Aug 23, 2017 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.