Home Database Mysql Tutorial 自动恢复MySQL数据库中日志文件实操

自动恢复MySQL数据库中日志文件实操

Jun 07, 2016 pm 04:11 PM
mysql recover database document article log automatic

以下的文章主要是教会你如何自动恢复MySQL数据库中的日志文件的实际操作步骤,以及在对其进行实际操作小红那些的相关事项是值得我们大家注意的,我们大家都知道如果MySQL(和PHP搭配之最佳组合)服务器启用了二进制日志。 你可以使用MySQL(和PHP搭配之最佳组合

以下的文章主要是教会你如何自动恢复MySQL数据库中的日志文件的实际操作步骤,以及在对其进行实际操作小红那些的相关事项是值得我们大家注意的,我们大家都知道如果MySQL(和PHP搭配之最佳组合)服务器启用了二进制日志。

你可以使用MySQL(和PHP搭配之最佳组合)binlog工具来恢复从指定的时间点开始 (例如,从你最后一次备份)直到现在或另一个指定的时间点的数据。“自动恢复MySQL(和PHP搭配之最佳组合)binlog:用于处理二进制日志文件的实用工具”。

要想从二进制日志恢复数据,你需要知道当前二进制日志文件的路径和文件名。一般可以从选项文件(即my.cnf or my.ini,取决于你的系统)中找到路径。如果未包含在选项文件中,当服务器启动时,可以在命令行中以选项的形式给出。启用二进制日志的选项为--log-bin。要想确定当前的二进制日志文件的文件名,输入下面的MySQL(和PHP搭配之最佳组合)语句:

<ol class="dp-xml"><li class="alt"><span><span>SHOW BINLOG EVENTS G </span></span></li></ol>
Copy after login

你还可以从命令行输入下面的内容:

<ol class="dp-xml"><li class="alt"><span><span>MySQL(和PHP搭配之最佳组合) </span><span class="attribute">--user</span><span>=</span><span class="attribute-value">root</span><span> -pmy_pwd -e 'SHOW BINLOG EVENTS G' </span></span></li></ol>
Copy after login

将密码my_pwd替换为服务器的root密码。

1. 指定恢复时间

对于MySQL(和PHP搭配之最佳组合) 4.1.4,可以在自动恢复MySQL(和PHP搭配之最佳组合)binlog语句中通过--start-date和--stop-date选项指定DATETIME格式的起止时间。举例说明,假设在今天上午10:00(今天是2006年4月20日),执行SQL语句来删除一个大表。要想恢复表和数据,你可以恢复前晚上的备份,并输入:

MySQL(和PHP搭配之最佳组合)binlog --stop-date="2005-04-20 9:59:59" /var/log/MySQL(和PHP搭配之最佳组合)/bin.123456

| MySQL(和PHP搭配之最佳组合) -u root -pmypwd

该命令将恢复截止到在--stop-date选项中以DATETIME格式给出的日期和时间的所有数据。如果你没有检测到几个小时后输入的错误的SQL语句,可能你想要恢复后面发生的活动。根据这些,你可以用起使日期和时间再次运行MySQL(和PHP搭配之最佳组合)binlog:

<ol class="dp-xml">
<li class="alt"><span><span>MySQL(和PHP搭配之最佳组合)binlog </span><span class="attribute">--start-date</span><span>=</span><span class="attribute-value">"2005-04-20 10:01:00"</span><span> /var/log/MySQL(和PHP搭配之最佳组合)/bin.123456  </span></span></li>
<li><span>| MySQL(和PHP搭配之最佳组合) -u root -pmypwd  </span></li>
</ol>
Copy after login

在该行中,从上午10:01登录的SQL语句将运行。组合执行前夜的转储文件和MySQL(和PHP搭配之最佳组合)binlog的两行可以将所有数据恢复到上午10:00前一秒钟。你应检查日志以确保时间确切。下一节介绍如何实现。

2. 指定恢复位置

也可以不指定日期和时间,而使用自动恢复MySQL(和PHP搭配之最佳组合)binlog的选项--start-position和--stop-position来指定日志位置。它们的作用与起止日选项相同,不同的是给出了从日志起的位置号。使用日志位置是更准确的恢复方法,特别是当由于破坏性SQL语句同时发生许多事务的时候。要想确定位置号,可以运行MySQL(和PHP搭配之最佳组合)binlog寻找执行了不期望的事务的时间范围,但应将结果重新指向文本文件以便进行检查。操作方法为:

<ol class="dp-xml">
<li class="alt"><span><span>MySQL(和PHP搭配之最佳组合)binlog </span><span class="attribute">--start-date</span><span>=</span><span class="attribute-value">"2005-04-20 9:55:00"</span><span> </span><span class="attribute">--stop-date</span><span>=</span><span class="attribute-value">"2005-04-20 10:05:00"</span><span> </span></span></li>
<li>
<span>/var/log/MySQL(和PHP搭配之最佳组合)/bin.123456 </span><span class="tag">></span><span> /tmp/MySQL(和PHP搭配之最佳组合)_restore.sql   </span>
</li>
</ol>
Copy after login

该命令将在/tmp目录创建小的文本文件,将显示执行了错误的SQL语句时的SQL语句。你可以用文本编辑器打开该文件,寻找你不要想重复的语句。如果二进制日志中的位置号用于停止和继续恢复操作,应进行注释。用log_pos加一个数字来标记位置。使用位置号恢复了以前的备份文件后,你应从命令行输入下面内容:

<ol class="dp-xml">
<li class="alt"><span><span>MySQL(和PHP搭配之最佳组合)binlog </span><span class="attribute">--stop-position</span><span>=</span><span class="attribute-value">"368312"</span><span> /var/log/MySQL(和PHP搭配之最佳组合)/bin.123456  </span></span></li>
<li><span>| MySQL(和PHP搭配之最佳组合) -u root -pmypwd  </span></li>
<li class="alt">
<span>MySQL(和PHP搭配之最佳组合)binlog </span><span class="attribute">--start-position</span><span>=</span><span class="attribute-value">"368315"</span><span> /var/log/MySQL(和PHP搭配之最佳组合)/bin.123456  </span>
</li>
<li><span>| MySQL(和PHP搭配之最佳组合) -u root -pmypwd  </span></li>
</ol>
Copy after login

上面的第1行将恢复到停止位置为止的所有事务。下一行将恢复从给定的起始位置直到二进制日志结束的所有事务。因为MySQL(和PHP搭配之最佳组合)binlog的输出包括每个SQL语句记录之前的SET TIMESTAMP语句,恢复的数据和相关自动恢复MySQL(和PHP搭配之最佳组合)日志将反应事务执行的原时间。


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the &quot;MySQL Native Password&quot; plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

See all articles