简体   繁体   English

MySQL还原不一致的数据库

[英]MySQL restoring inconsistent database

As a follow up to this question: Is copying /var/lib/mysql a good alterntive to mysqldump? 作为此问题的后续措施: 将/ var / lib / mysql复制到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)? 如果我不停止数据库服务器,并且我的表不一致,那么MySQL仍然可以从中恢复(通过删除不一致的行)吗? 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. 我一直在通过备份/var/lib/mysql进行备份,但是我从来没有使用过它们。 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. 一致的快照(所有时间上来自同一时刻的所有数据)都很好-这是(希望)在崩溃中发生的事情,而MySQL(特别是InnoDB)经过精心设计可从中恢复,尽管启动可能需要一些时间因为它确实崩溃恢复。 For MyISAM tables - well you are on your own. 对于MyISAM表-好吧,您自己一个人。

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. MySQL将尝试,但不能保证它将从这种情况下恢复。

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. 因此,您可以使用LVM快照之类的工具来及时获取一致的快照,或者将mysqldump与--single-transaction一起使用,或者在备份表时使它们成为只读表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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