简体   繁体   中英

MySQL restoring inconsistent database

As a follow up to this question: Is copying /var/lib/mysql a good alterntive to mysqldump?

If I don't stop the database server, and my tables are inconsistent, can MySQL still recover from this (by removing the inconsistent rows)? Or is the backup entirely useless?

I've been doing my backups by backing up /var/lib/mysql for a long time... but I've never had to use them. It'd be terrible to find out I couldn't if I had to (after the fact, that is).

A consistent snapshot (all of the data from the same instant in time) is fine - this is (hopefully) what happens in a crash and MySQL (specifically InnoDB) is engineered to recover from this, although it may take a while to start up as it does crash recovery. For MyISAM tables - well you are on your own.

The problem is that it takes a while to copy a file and the files may be changing as you are copying them, so your backup file may be an inconsistent snapshot. The start of the file containing older data than the end! Additionally all the files need to be in sync wrt each other. MySQL will try but there is no guarantee that it will recover from this condition.

So you can use something like LVM snapshots to get a consistent snapshot in time or use mysqldump with --single-transaction, or make the tables read-only while you are backing them up.

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