Database binlog data recovery

Whether to open binlog (on turned on)

show variables like 'log_bin'+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | ON    |
+---------------+-------+

Open (no version 8.0+ my.ini after I install zip unzip version used whenever possible [general] enabled by default)
Windows under any possible C: my.ini \ ProgramData under \ mysql, and can not find One

Binary Logging # 
log -bin = the binlog (also designated path) 
the binlog -format = the ROW

To find my.cnf under linux in general /etc/my.cof ..

server-id=1
log-bin=/var/lib/mysql/binlog
And then restart the inquiry that opened 


binlog log query
show master logs;
+---------------+-----------+-----------+
| Log_name      | File_size | Encrypted |
+---------------+-----------+-----------+
| binlog.000009 |       178 | No        |
| binlog.000010 |       178 | No        |
| binlog.000011 |       178 | No        |
| binlog.000012 |      1618 | No        |
| binlog.000013 |       178 | No        |
| binlog.000014 |       178 | No        |
| binlog.000015 |       178 | No        |
| binlog.000016 |       178 | No        |
| binlog.000017 |       178 | No        |
| binlog.000018 |      2583 | No        |
| binlog.000032 |  66276708 | No        |
+---------------+-----------+-----------+
show binlog events;
+---------------+-----+----------------+-----------+-------------+-----------------------------------+
| Log_name      | Pos | Event_type     | Server_id | End_log_pos | Info                              |
+---------------+-----+----------------+-----------+-------------+-----------------------------------+
| binlog.000009 |   4 | Format_desc    |         1 |         124 | Server ver: 8.0.16, Binlog ver: 4 |
| binlog.000009 | 124 | Previous_gtids |         1 |         155 |                                   |
| binlog.000009 | 155 | Stop           |         1 |         178 |                                   |
+---------------+-----+----------------+-----------+-------------+-----------------------------------+
show binary logs;
+---------------+-----------+-----------+
| Log_name      | File_size | Encrypted |
+---------------+-----------+-----------+
| binlog.000009 |       178 | No        |
| binlog.000010 |       178 | No        |
| binlog.000011 |       178 | No        |
| binlog.000012 |      1618 | No        |
| binlog.000013 |       178 | No        |
| binlog.000014 |       178 | No        |
| binlog.000015 |       178 | No        |
| binlog.000016 |       178 | No        |
| binlog.000017 |       178 | No        |
| binlog.000018 |      2583 | No        |
| binlog.000032 |  66276708 | No        |
+---------------+-----------+-----------+
show binlog events in 'binlog.000016';//查询指定binlog

 

(There mysqlbinlog command, if no global variables, you need to perform in the bin directory of mysql. To enter the login mysql binlog other related commands)

SQL parsed into read (according to sql, to find the position of a point)

mysqlbinlog --base64-output=DECODE-ROWS -v binlog.000067 > d:/1.sql
mysqlbinlog --start-datetime="2019-11-06 17:18:20" --stop-datetime="2019-11-06 17:21:21" binlog.000067 > D://test121.sql
show master status;/*主log状态*/
show VARIABLES like 'BINLOG_format';/*binlog格式*/
SHOW BINLOG EVENTS in 'binlog.000067';/*查询binlog详情*/
BINARY logs Show; / * check so binlog file * / 
Show Master logs; / * supra * / 
/ * Non-mysql performed below * / 
the mysqlbinlog --start-position = 313 --stop-position = 436 binlog. 000 067 > D: test.sql \\; / * the mysql data directory, specify the export file * / 
Show the binlog Events in  ' binlog.000067 '  from  313 limit 2 , 10 \ G; 
the mysqlbinlog the binlog. 000 067 > D: \\ test.sql;

Data Recovery

mysqlbinlog --no-defaults --database=geeRunner --start-datetime="2017-09-17 07:21:09" --stop-datetime="2017-09-19 07:59:50" binlogs.000080 > sanjiaomao.txt
mysqlbinlog --no-defaults --database=geeRunner --start-datetime="2017-09-17 07:21:09" --stop-datetime="2017-09-19 07:59:50" binlogs.000080 | more
View only update operation
mysqlbinlog --no-defaults --database=raceEnroll  binlogs.000078 |grep update |more
1, recover deleted data from 2015-12-15 11:20 to 2015-12-15 17:20
mysqlbinlog -d test --start-date="2015-12-15 11:20" --stop-date="2015-12-15 17:20"  binlog.000004  |mysql -uroot -p
2, the recovery operation between 10,000 to 20,000 position of the point
mysqlbinlog -d test --start-position="10000" --stop-position="20000"  binlog.000004  |mysql -uroot -p
3. can be resolved before a * .sql file
Enter mysql, executed after logging 
Source / the Data / * .sql

Combat Description: 1, binlog log is valid, the expiration of the data can not be recovered 2, if the table structure is modified, deleted data in order to recover before the table structure changes, you must first restore the table structure, otherwise it can not be recovered 3 , binlog log generally have multiple, sometimes you want to restore data across multiple log files inside

 Binlog recover data once recorded

Recovery Test windows
1-readable file is parsed (binlog server pulled under the windows)
the mysqlbinlog --base64 the DECODE-ROWS-Output = -v binlog.000067> D: /1.sql
2. Try binlog analysis on linux readable
successfully resolved a bit surprised. .
3. Locate the latest binlog
recovery position AT 36.64374 million #
log information after the re-construction of the table
4. Try using binlog restore data to localhost in
mysqlbinlog --stop-position = 36643740 binlog.000067> d: /1.sql
derived from the position binlog recovery information
5. 1.sql data recovery
can be restored. . But the result is still not the library
that I delete the recovery point contains the library operations
modify the node to 36,643,625 AT
6. partial incremental recovery was successful
database backup mysql log in under use of
EG: use db;
Source 1.sql;
data that is to restore the data log contains time information to complete

tip: binlog.000067 above may be the full path
mysqlbinlog --stop-position 36643625 C: \ Users \ admin \ Desktop \ binlog.000031> C: \ Users \ admin \ Desktop \ 1.sql

Note: The same operation under linux, must first restore the backup data structure and the portion prior to recovery .
For example, to back up No. 11.11, then use the binlog file date to at least the number 11.11 has all binlog documents and,
when possible multiple sql file, only to ensure full recovery. Also, if data backup binlog data with duplicate insert operation, the data will be repeated, so
select the recovery point or binlog time is very important. Finally, there are near misses.

Guess you like

Origin www.cnblogs.com/UBEING/p/12307605.html