MySQL restores data through binlog

MySQL itself does not provide the flashback function, so it is a lot of trouble for us to restore data after misoperation. If we do not need other people's plug-ins, the following method can restore

1. Binlog must be turned on and must be in ROW mode. If this premise is not satisfied, then the following method cannot restore the data.
Check whether binlog is enabled show variables like '%log_bin%'
Check the binlog mode show variables like '%binlog_format%'
Add these two lines to my.ini
# binlog log file name prefix
log-bin=mysql_bin
# binlog format
binlog_format=ROW

2. Delete a piece of data from the user table DELETE from user where name='Luffy', at this time a binlog will be generated in the data folder


3. Use the show BINARY logs; command to view the binlog list


4.000006 is the largest, this latest log is recorded in In 000006, use the show binlog events in 'mysql_bin.000006'; command to view the specific details of the binlog 000006, mainly by looking at start-pos and stop-pos

. It can be seen from the figure that the last operation starts from pos=14043 and ends at pos =14171 End

5. The command line cd to the MySQL bin directory my path is E:\program\db\mysql-5.6.17-winx64\bin

6. Use the mysqlbinlog command that comes with mysql to view the specific sql of bin_log.000006, the command is
E:\program\db\mysql-5.6.17-winx64\bin>mysqlbinlog --start-position=14043 --stop-position =14171 -v -v ../data/mysql_bin.000006

We have already seen sql, if there is only English in the data, there is nothing, if there is Chinese in the data, there will be garbled characters, mysqlbinlog has a parameter specifying the encoding, I tried , is of no use. -v means display sql, -v -v displays the line definition, you can use mysqlbinlog --help to view the meaning of each

parameter -5.6.17-winx64\bin>mysqlbinlog --start-position=14043 --stop-position=14171 -v -v ../data/mysql_bin.000006>d:\3.sql
export this viewing result to D disk, and then use notepad++ to open it

. The display is normal. If there is a problem of garbled characters in Linux, export to Windows and open it with notepad++

. Second column = Luffy's data was deleted. Now that you know the specific information of the deleted data, you can manually restore this data. If the amount of data is too large, you can use some other tools or write a program to restore it.

mysql -uroot -p dbname < 3.sql can also

refer to : http://www.cnblogs.com/kevingrace/p/5904800.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326879052&siteId=291194637