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"