如何使用MYSQL数据库进行备份数据恢复
数据库毁坏发生的原因有许多,且程度各不相同。如果幸运的话,可能是一两个表的小毁坏(例如,如果您的机器由于断电而暂时停机)。如果不是这 样,可能需要置换整个的数据目录(例如,如果某个磁盘瘫痪而且数据目录在它上)。在其他情况下也需要恢复操作,例
数据库毁坏发生的原因有许多,且程度各不相同。如果幸运的话,可能是一两个表的小毁坏(例如,如果您的机器由于断电而暂时停机)。如果不是这 样,可能需要置换整个的数据目录(例如,如果某个磁盘瘫痪而且数据目录在它上)。在其他情况下也需要恢复操作,例如,当用户错误地删除数据库或表时,或者 错误地删除表的内容时。不论这些不幸的事件发生是由于什么原因,都需要恢复它们。
如果表被毁坏但没有丢失,可试着用myisamchk 或isamchk 来修复它们。如果修复实用程序能修复它们,就根本没有必要使用备份文件。如果表被丢失或不能修复,则需要恢复它们。
恢复过程包括两个信息源:备份文件和更新日志。备份文件将表恢复到进行该备份时的状态。但是,在备份和故障发生这段时间中,表通常已经被修改。 更新日志包含了用来完成这些修改的查询。可以通过将更新日志作为对mysql的输入来重复这些查询(这就是为什么需要更新日志的原因。如果您还没有使更新 日志有效,现在赶快做,并在进一步读取之前生成一个新的备份)。
恢复过程根据必须恢复的信息的多少而变化。事实上,恢复整个数据库比恢复单个的表要容易,因为对数据库应用更新日志比对表要容易。
恢复整个数据库
首先,如果要恢复的数据库是含有授权表的mysql数据库,将需要使用--skip-grant-tables选项运行服务器。否则,服务器将 抱怨无法找到授权表。在恢复表之后,执行mysqladmin 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 命令产生更新日志文件的单列列表,更新日志文件根据服务器生成的顺序进行排序(要知道,如果您修改了其中的任何文件,排序的顺序都将改变,这将导致更新日志按错误的顺序使用)。
您很可能必须使用某些更新日志。例如,如果自备份以来所产生的日志命名为update.392、pdate.393 等等,可以重新运行它们中的命令: % mysql--one-database db_name
如果正在运行恢复并打算使用更新日志恢复由于失策的DROP DATA BASE、DROPTABLE或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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA
