mysql增量备份binlog日志

增量备份也有很多我就来讲下用binlog日志做增量备份及恢复吧。

binlog日志概述
什么是binlog日志
也称做 二进制日志
mysql服务日志文件的一种
记录除查询之外的所有SQL命令
可用于数据备份及恢复
配置mysql主从同步的必要条件

启用日志
· server_id=数字 //指定id值(1-255)
log_bin[=目录/文件名] //启用binlog日志
max_binlog_size=数值m //指定日志文件容量,默认1G

  写到mysql主配置文件中案例如下


vim /etc/my.cnf
[mysql]
.........
log_bin
server_id=51
max_binlog_size=2048m
:wq
  systemctl restart mysqld			//修改完配置文件后重启服务

启用日志(续1)
binlog相关文件
主机名-bin.index //索引文件
主机名-bin.000001 //第一个二进制文件
主机名-bin.000002 //第二个二进制文件

手动生成新的日志文件命令有入下所示:

systemctl restart mysqld      //这是重启服务也可以刷新日志文件
mysql > flush logs; 					//在数据库中用这个也可以刷新日志文件
mysql -uroot -p123456 -e 'flush log'     //在命令行中这样也可以刷新日志文件
mysqldump --flush-logs                //这个也是在命令行中刷新日志文件
//这个就看你自己想用那一个了

清理日志文件
删除指定编号的binlog日志文件命令格式
mysql > purge master logs to “binlog文件名”
删除所有binlog日志, 重建新日志命令格式
mysql > reset master;

分析日志文件
查看日志文件当前记录格式:
mysql > show variables like “binlog_format”;
一共有三种模式分别是:
statement 报表模式
row 行模式
mixed 混合模式

修改日志记录格式

[root@localhost~]# vim /etc/my.cnf
[mysql]
.........
binlog_format="名称"
systemctl restart mysqld 		//重启服务

在这里插入图片描述

恢复数据
基本思路
使用 mysqlbinlog 提取历史SQL命令操作
用管道交给mysql命令执行
命令格式
mysqlbinlog 日志文件 | mysql -uroot -p123456
应用示列
使用编号为1的日志文件恢复数据

 mysqlbinlog /mylog/plj-bin.000001 | mysql -uroot -p123456
Legal Notice Copyright © 2017 Veritas Technologies LLC. All rights reserved. Veritas and the Veritas Logo are trademarks or registered trademarks of Veritas Technologies LLC or its affiliates in the U.S. and other countries. Other names may be trademarks of their respective owners. This product may contain third party software for which Veritas is required to provide attribution to the third party (“Third Party Programs”). Some of the Third Party Programs are available under open source or free software licenses. The License Agreement accompanying the Software does not alter any rights or obligations you may have under those open source or free software licenses. Please see the Third Party Legal Notice Appendix to this Documentation or TPIP ReadMe File accompanying this product for more information on the Third Party Programs. The product described in this document is distributed under licenses restricting its use, copying, distribution, and decompilation/reverse engineering. No part of this document may be reproduced in any form by any means without prior written authorization of Veritas Technologies LLC and its licensors, if any. THE DOCUMENTATION IS PROVIDED "AS IS" AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID. VERITAS TECHNOLOGIES LLC SHALL NOT BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH THE FURNISHING, PERFORMANCE, OR USE OF THIS DOCUMENTATION. THE INFORMATION CONTAINED IN THIS DOCUMENTATION IS SUBJECT TO CHANGE WITHOUT NOTICE. The Licensed Software and Documentation are deemed to be commercial computer software as defined in FAR 12.212 and subject to restricted rights as defined in FAR Section 52.227-19 "Commercial Computer Software - Restricted Rights" and DFARS 227.7202, et seq. "Commercial Computer Software and Commercial Computer Software Documentation," as applicable, and any successor regulations, whether delivered by Veritas as on premises or hosted services. Any use, modification, reproduction release, performance, display or disclosure of the Licensed Software and Documentation by the U.S. Government shall be solely in accordance with the terms of this Agreement.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值