Mysql入门系列:使用MYSQL备份数据恢复_MySQL
数据库毁坏发生的原因有许多,且程度各不相同。如果幸运的话,可能是一两个表的小毁坏(例如,如果您的机器由于断电而暂时停机)。如果不是这样,可能需要置换整个的数据目录(例如,如果某个磁盘瘫痪而且数据目录在它上)。在其他情况下也需要恢复操作,例如,当用户错误地删除数据库或表时,或者错误地删除表的内容时。不论这些不幸的事件发生是由于什么原因,都需要恢复它们。
如果表被毁坏但没有丢失,可试着用myisamchk 或isamchk 来修复它们。如果修复实用程序能修复它们,就根本没有必要使用备份文件。表的修复过程将在第13 章讨论。如果表被丢失或不能修复,则需要恢复它们。
恢复过程包括两个信息源:备份文件和更新日志。备份文件将表恢复到进行该备份时的状态。但是,在备份和故障发生这段时间中,表通常已经被修改。更新日志包含了用来完成这些修改的查询。可以通过将更新日志作为对mysql的输入来重复这些查询(这就是为什么
应该允许更新日志的原因。如果您还没有使更新日志有效,现在赶快做,并在进一步读取之前生成一个新的备份)。
恢复过程根据必须恢复的信息的多少而变化。事实上,恢复整个数据库比恢复单个的表要容易,因为对数据库应用更新日志比对表要容易。
恢复整个数据库
首先,如果要恢复的数据库是含有授权表的mysql数据库,将需要使用- - s k i p - g r a n t - tables选项运行服务器。否则,服务器将抱怨无法找到授权表。在恢复表之后,执行mysqla d m i n flush-privileges 来告诉服务器加载授权表,并用它们启动。
将原数据库目录的内容拷贝到其他的地方。例如,您可能会在稍后用它们进行崩溃表的事后分析检查(post-mortem examination)。
用最新的备份文件重新加载数据库。如果您打算使用由mysqldump 加载的文件,则需要将它们作为mysql的输入。如果打算使用从数据库中直接拷贝的文件(如,用tar 或c p),则将它们直接拷贝回到该数据库目录中。但是,在这种情况下,应该在拷贝这些文件之前关闭服务器,然后再重新启动它。
用更新日志重做在进行备份后又修改了数据库表的查询。对于所有可用的更新日志,可使用它作为mysql的输入。指定--one-database 选项,使mysql只对想要恢复的数据库执行查询。如果您知道需要使用所有的更新日志文件,可在包含日志的目录中使用
下列命令:
% ls -t -r -l update.(0-9)* | xargs cat | mysql--one-database db_name
ls 命令产生更新日志文件的单列列表,更新日志文件根据服务器生成的顺序进行排序(要知道,如果您修改了其中的任何文件,排序的顺序都将改变,这将导致更新日志按错误的顺序使用)。
您很可能必须使用某些更新日志。例如,如果自备份以来所产生的日志命名为up date . 3 9 2、update.393 等等,可以重新运行它们中的命令:
% mysql--one-database db_name
% mysql--one-database db_name
。。。
如果正在运行恢复并打算使用更新日志恢复由于失策的DROP DATA B A S E、D R O P TABLE 或DELETE 语句而丢失的信息,应确保先从更新日志中删除这些语句。
恢复单个的表
恢复单个表是很困难的。如果有通过mysqldump 生成的备份文件并且它恰好不包含您想要的表数据,则需要抽取相关的行并用它们作为mysql的输入,这部分较容易。困难的是抽取应用于该表的更新日志的片段。您会发现: mysql_find_rows 实用程序对这方面有帮助,它可以从更新日志中抽取多行查询。
另一种可能性是用另一个服务器恢复整个数据库,然后将所要的该表的文件拷贝到原始数据库中。这实际很容易!在将文件拷贝回数据库目录时,应确保原始数据库的服务器关闭。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Windows 7 users encounter the phenomenon that the system registry file is missing or damaged when starting up. How to solve this situation? You first force restart the computer, then press the F8 key, select safe mode in the opened page, then find the command prompt in the menu bar to open, enter the SFC/SCANNOW command and press Enter, then the system will automatically start the computer Repair missing or corrupted installation files. What to do if the Windows 7 system registry file is lost or damaged 1. After the first power-on self-test, immediately hold down the F8 key, use the arrow keys to select safe mode, and hit Enter. 2. Then click the Start button, select Command Prompt, and run as an administrator. 3. Finally, enter SFC/ in the pop-up prompt.

Many friends don’t know how to recover diskgenius data, so the editor will share the relevant tutorials on diskgenius data recovery. Let’s take a look. I believe it will be helpful to everyone. First, in the hard disk partition diagram above the main interface of DiskGenius, you can directly select the target partition and right-click. Then, in the shortcut menu that pops up, find and click the "Deleted or formatted file recovery" menu item, as shown in the figure. In the second step, the recovery options window pops up and make sure to check the three options of "Recover Deleted Files", "Complete Recovery" and "Extra Scan for Known File Types". Step 3: Click the "Select File Type" button on the right and specify the files you need to recover in the pop-up window

ThinkPHP6 data backup and recovery: ensuring data security With the rapid development of the Internet, data has become an extremely important asset. Therefore, the security of data is of great concern. In web application development, data backup and recovery are an important part of ensuring data security. In this article, we will introduce how to use the ThinkPHP6 framework for data backup and recovery to ensure data security. 1. Data backup Data backup refers to copying or storing the data in the database in some way. This way even if the data

Solution to the problem of PHP parameter loss In the process of developing PHP programs, we often encounter the problem of parameter loss. This may be caused by incomplete parameters passed by the front end or incorrect way of receiving parameters by the back end. In this article, we will provide some solutions to the problem of missing parameters in PHP, along with specific code examples. 1. Front-end parameter passing problem Use the GET method to pass parameters. When using the GET method to pass parameters, the parameters will be appended to the requested URL in the form of URL parameters. When receiving parameters in the backend

How to solve a broken hard disk sector? A broken hard disk sector is a common hardware failure, which may cause data loss and affect computer performance. It is very important to understand and solve the problem of bad hard drive sectors. This article will introduce the concept of hard disk sectors, discuss common causes of bad hard disk sectors and solutions. 1. What are hard disk sectors? Before introducing how to solve the problem of bad hard disk sectors, let’s first understand what hard disk sectors are. A hard disk sector is the smallest readable and writable unit on a hard drive. It is a small section of space on a hard drive. It is

Laravel is a popular PHP web application framework that provides many fast and easy ways to build efficient, secure and scalable web applications. When developing Laravel applications, we often need to consider the issue of data recovery, that is, how to recover data and ensure the normal operation of the application in the event of data loss or damage. In this article, we will introduce how to use Laravel middleware to implement data recovery functions and provide specific code examples. 1. What is Lara?

How to quickly recover from failures and errors encountered by MySQL database? MySQL is a widely used open source relational database management system that many applications and websites rely on to store and manage data. However, database failures and errors are inevitable, which may result in data loss or application failure to function properly. When encountering a MySQL database failure or error, it is very important to recover the database quickly and effectively. This article will introduce some methods to quickly restore MySQL database. Determine the type of fault and error before starting

Methods for data recovery on Huawei computers: 1. Recover from the Recycle Bin; 2. Use data recovery software; 3. Recover from backup; 4. Use Huawei Cloud services. Detailed introduction: 1. Recover from the Recycle Bin. If the data on the Huawei computer is deleted and has not been overwritten by new files, the data can be recovered from the Recycle Bin; 2. Use data recovery software. If the data is deleted from the Recycle Bin, If there is no data that needs to be restored, or the data has been overwritten, you can use data recovery software to restore the data in Huawei computers; 3. Restore from backup, if Huawei computers, etc.
