MySQL/InnoDB崩溃重启的主要原因及文件拷贝致崩溃滞后性咨询
Great question—this is a classic pitfall with MySQL's InnoDB engine, and that week-long delay between your risky file copy and the crash isn't random. Let's break down exactly why it happens:
1. InnoDB's Lazy Consistency Checks
InnoDB doesn't scan every single page in your .ibd files on startup to verify consistency. Instead, it only checks page integrity when the page is actually accessed (read, written, or flushed from the buffer pool).
When you copied the .frm and .ibd files over, most of the corrupted or mismatched index pages were sitting idle on disk. It took a week for your application's queries, writes, or background maintenance tasks to hit those specific pages. Once they did, InnoDB detected the index mismatch and started throwing warnings.
2. The Buffer Pool Acts as a "Buffer" (Literally)
InnoDB relies heavily on its Buffer Pool to cache frequently used data and index pages. Right after the copy, the buffer pool was either empty or populated with pages from other tables. The corrupted pages stayed on disk until they were needed.
As your application's workload grew or shifted to touch those unused index ranges, the bad pages were loaded into the buffer pool. At that point, InnoDB noticed the checksum mismatches, index entry inconsistencies, or mismatched table space IDs between the .frm and .ibd files.
3. Transaction Logs Masked the Issue Temporarily
InnoDB uses redo and undo logs to maintain transaction consistency. When you copied the files without properly shutting down the source database or using a consistent backup tool, there were likely uncommitted transactions or incomplete log entries that didn't get synced to the .ibd files.
For a while, the transaction logs could "patch over" the inconsistencies—InnoDB uses them to replay recent changes during startup or recovery. But once those logs were overwritten (InnoDB cycles through log files), or when an operation needed to access a page that wasn't covered by the remaining logs, the underlying corruption became impossible to hide.
4. Background Threads Take Time to Detect Issues
InnoDB runs background threads that perform periodic tasks like page cleaning, checkpointing, and consistency checks. These threads don't scan every page immediately—they work in batches over time.
It might have taken several days for these threads to reach the corrupted index pages in your copied tables. Once they did, they flagged the mismatches as warnings, and as more corrupted pages were discovered, the system became unstable until it finally crashed.
Key Takeaway
Directly copying .frm and .ibd files is never safe for InnoDB. These files contain tightly coupled metadata (like table space IDs, transaction IDs, and page checksums) that need to be synchronized properly. Tools like mysqldump, mysqlpump, or Percona Xtrabackup handle this consistency by taking logical or consistent physical backups, avoiding these hidden corruption issues entirely.
内容的提问来源于stack exchange,提问作者Tyler Christian

