Mysql通过binlog日志文件恢复数据

mysqlbinlog 官方操作文档:https://dev.mysql.com/doc/refman/5.6/en/mysqlbinlog.html

 windows和linux下操作请找到mysqlbinlog可执行命令所在位置 。

数据库需要开启log_bin功能并设置开启binlog行级模式(ROW):

操作选项:

Option NameDescriptionIntroduced
--base64-outputPrint binary log entries using base-64 encoding 
--bind-addressUse specified network interface to connect to MySQL Server5.6.1
--binlog-row-event-max-sizeBinary log max event size 
--character-sets-dirDirectory where character sets are installed 
--connection-server-idUsed for testing and debugging. See text for applicable default values and other particulars.5.6.20
--databaseList entries for just this database 
--debugWrite debugging log 
--debug-checkPrint debugging information when program exits 
--debug-infoPrint debugging information, memory, and CPU statistics when program exits 
--default-authAuthentication plugin to use5.6.2
--defaults-extra-fileRead named option file in addition to usual option files 
--defaults-fileRead only named option file 
--defaults-group-suffixOption group suffix value 
--disable-log-binDisable binary logging 
--exclude-gtidsDo not show any of the groups in the GTID set provided5.6.5
--force-if-openRead binary log files even if open or not closed properly 
--force-readIf mysqlbinlog reads a binary log event that it does not recognize, it prints a warning 
--helpDisplay help message and exit 
--hexdumpDisplay a hex dump of the log in comments 
--hostConnect to MySQL server on given host 
--include-gtidsShow only the groups in the GTID set provided5.6.5
--local-loadPrepare local temporary files for LOAD DATA in the specified directory 
--login-pathRead login path options from .mylogin.cnf5.6.6
--no-defaultsRead no option files 
--offsetSkip the first N entries in the log 
open_files_limitSpecify the number of open file descriptors to reserve 
--passwordPassword to use when connecting to server 
--plugin-dirDirectory where plugins are installed5.6.2
--portTCP/IP port number for connection 
--print-defaultsPrint default options 
--protocolConnection protocol to use 
--rawWrite events in raw (binary) format to output files 
--read-from-remote-masterRead the binary log from a MySQL master rather than reading a local log file5.6.5
--read-from-remote-serverRead binary log from MySQL server rather than local log file 
--result-fileDirect output to named file 
--secure-authDo not send passwords to server in old (pre-4.1) format5.6.17
--server-idExtract only those events created by the server having the given server ID 
--server-id-bitsTell mysqlbinlog how to interpret server IDs in binary log when log was written by a mysqld having its server-id-bits set to less than the maximum; supported only by MySQL Cluster version of mysqlbinlog 
--set-charsetAdd a SET NAMES charset_name statement to the output 
--shared-memory-base-nameName of shared memory to use for shared-memory connections 
--short-formDisplay only the statements contained in the log 
--skip-gtidsDo not print any GTIDs; use this when writing a dump file from binary logs containing GTIDs.5.6.5
--socketThe Unix socket file or Windows named pipe to use 
--ssl-crlFile that contains certificate revocation lists5.6.3
--ssl-crlpathDirectory that contains certificate revocation-list files5.6.3
--ssl-modeDesired security state of connection to server5.6.30
--start-datetimeRead binary log from first event with timestamp equal to or later than datetime argument 
--start-positionRead binary log from first event with position equal to or greater than argument 
--stop-datetimeStop reading binary log at first event with timestamp equal to or greater than datetime argument 
--stop-neverStay connected to server after reading last binary log file 
--stop-never-slave-server-idSlave server ID to report when connecting to server 
--stop-positionStop reading binary log at first event with position equal to or greater than argument 
--to-last-logDo not stop at the end of requested binary log from a MySQL server, but rather continue printing to end of last binary log 
--userMySQL user name to use when connecting to server 
--verboseReconstruct row events as SQL statements 
--verify-binlog-checksumVerify checksums in binary log5.6.1
--versionDisplay version information and exit

操作语法:

格式:mysqlbinlog 日志文件 参数 | mysql -u用户名 -p密码

mysqlbinlog liangck.000001 | mysql -uroot –p123456  表示 全部恢复

mysqlbinlog liangck.000002 --start-pos=417 --stop-pos=773 | mysql -uroot -p123456 表示 从417至773位置

mysqlbinlog liangck.000002 --stop-pos=773 | mysql -uroot -p123456  表示 从头至773位置

mysqlbinlog liangck.000002 --start-pos=417 | mysql -uroot -p123456 表示 从417至尾 位置 

mysqlbinlog liangck.000002 --start-datetime="2004-12-25 11:25:56"  | mysql -uroot -p123456 日期参数和pos同理

 更多参考:

超级有用的15个mysqlbinlog命令

Linux 上通过binlog文件 恢复mysql 数据库详细步骤

windows下mysqlbinlog二进制恢复

MySQL的binlog恢复(Windows下) 

关闭binlog恢复错误问题处理:

https://yq.aliyun.com/articles/700466

注意:如果过程中报错请附上编码设置选项。

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值