Mysqlbinlog to restore MySQL database data "simple experience"

Source: Internet
Author: User

Objective

A simple experience for beginners only.

Prerequisite: MySQL has turned on the Binlog log feature. Can self-Baidu, recommended address--------->windows How to turn on the MySQL log function

Experience Goal: Add a new piece of data to the database table, then delete the data, and then binlog to recover the deleted data.

Environment

WINDOWS10;

mysql5.7.21;

Database Initial state

You can see only two records.

Data preparation

To add a piece of data first

And then delete this data

Using commands

Mysql> Show master status;

Check the latest log written in that log file, as follows

You can see that the log is written in the mysql-bin.000002 configuration file.

Using commands

inch ' mysql-bin.000002 ';

To view the contents of a log:

The red box is the log that just inserted the data, the red box below is to delete the log of the data that day. From the contents of the red box can be seen, insert operation log start position is 937, the end is 1293, these two numbers to remember!!!

Next Exit MySQL

Execute mysql>exit; and you can

Start recovering data

The Mysqlbinlog command appeared.

Make sure you have added the command to the environment variable before executing the command, or you will need to go to the bin folder of the MySQL installation directory to execute the command.

Notice the three red squares in the above figure, and make a note:

First: Represents the starting position of the log to be restored;

Second: The end position of the log to be restored;

Third: The path of the log file used

When you're done, check the data sheet.

found that the data just deleted has been restored.

At this point, the goal has been achieved!

Mysqlbinlog to restore MySQL database data "simple experience"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.