如何用mysqldump进行全量和时间点备份

所属分类: 数据库 / Mysql 阅读数: 773
收藏 0 赞 0 分享

mysqldump在mysql中用于逻辑备份,虽然速度不快,但非常灵活,有很多功能,灵活使用的化绝对是利器。

首先思考一个问题,mysql为什么要备份,主要还是数据安全性,比如主库挂了,数据不小心被删除了,所以全量备份非常重要。

是从主库还是副库进行全量备份呢?

1:从主库

主库比较重要,但其实备份的时候并不会影响数据库

mysqldump --host= --user= --password= --single-transaction --master-data=1 --flush-logs --databases >~/db.log

—single-transaction 参数能够报纸一致性读,不会锁表,也就是备份的时候不影响数据更新。

it dumps the consistent state of the database at the time when START TRANSACTION was issued without blocking any applications.

因为一致性读,能够保证coordinates点的位置,即使备份时间很久,也能得出正确的同步位置点。

While a —single-transaction dump is in process, to ensure a valid dump file (correct table contents and binary log coordinates)

—master-data参数也很重要,导出的语句会包含CHANGE MASTER TO语句,包括备份语句同步到的二进制文件和位置点。

Use this option to dump a master replication server to produce a dump file that can be used to set upanother server as a slave of the master. It causes the dump output to include a CHANGE MASTER TO statement that indicates the binary log coordinates (file name and position) of the dumped server. These are the master server coordinates from which the slave should start replicating after you load the dump file into the slave.

—flush-logs会强制重新生成一个新的二进制文件,这样恢复的时候会比较方便。

2:从副库

感觉上从副库备份更安全。

mysqldump --host=--user= --password= --dump-slave=1 --flush-logs --apply-slave-statements --include-master-host-port --databases >~/db.log;

— dump-slave和—master-data参数很类似:

This option is similar to —master-data except that it is used to dump a replication slave server to produce a dump file that can be used to set up another server as a slave that has the same master as the dumped server. It causes the dump output to include a CHANGE MASTER TO statement that indicates the binary log coordinates (file name and position) of the dumped slave's master. These are the master server coordinates from which the slave should start replicating.

记住一点它获取的是主库的bin log coordinates(不是备份库的)

—dump-slave causes the coordinates from the master to be used rather than those of the dumped server

dump出来的语句会包含 — Position to start replication or point-in-time recovery from。

—apply-slave-statements会让dump语句中自动包含start和stop slave语句。—include-master-host-port包含主库的连接信息。

必须记住一点,即使有—single-transaction语句,—dump-slave也会暂停mysql同步,也就是备份库的数据是落后于主库的,所以一般自动化脚本在备份的时候会先摘除备份库。

This option causes mysqldump to stop the slave SQL thread before the dump and restart it again after.

3:如何进行时间点恢复

没有实战过,首先基于最近的一次全量备份进行恢复,然后将后续的binlog文件导入(如果这些文件还在的话),所以副库最好也备份binlog语句。

如果数据被误删除了,将备份点(—flush-logs发挥作用了)到今天凌晨的binlog语句导入进来,或者找到安全的binlog位置点进行恢复。至于如何跳过“危险语句”是比较难控制的。

以上就是如何用mysqldump进行全量和时间点备份的详细内容,更多关于mysqldump进行全量和时间点备份的资料请关注脚本之家其它相关文章!

更多精彩内容其他人还在看

简单了解标准SQL的update语句三种用法

这篇文章主要介绍了简单了解标准SQL的update语句三种用法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,,需要的朋友可以参考下
收藏 0 赞 0 分享

MySQL5.7.23解压版安装教程图文详解

这篇文章主要介绍了MySQL5.7.23解压版安装教程图文详解,本文图文并茂给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

python 连接数据库mysql解压版安装配置及遇到问题

今天学习python连接数据库,就想安装一下mysql数据库,没想到小小的数据库也遇到了不少挫折,所以我就把自己的安装过程以及问题写出来分享给大家,需要的朋友可以参考下
收藏 0 赞 0 分享

为什么说MySQL单表数据不要超过500万行

在本篇文章里小编给大家整理了一篇关于为什么说MySQL单表数据不要超过500万行的相关内容,有兴趣的朋友们阅读下吧。
收藏 0 赞 0 分享

基于python的mysql复制工具详解

python-mysql-replication 是基于python实现的 MySQL复制协议工具,我们可以用它来解析binlog 获取日志的insert,update,delete等事件 ,并基于此做其他业务需求。这篇文章主要介绍了基于python的mysql复制工具,需要的朋
收藏 0 赞 0 分享

mysql语句查询用户权限过程详解

这篇文章主要介绍了mysql语句查询用户权限过程详解,授予用户的权限可能分全局层级权限、数据库层级权限、表层级别权限、列层级别权限、子程序层级权限。,需要的朋友可以参考下
收藏 0 赞 0 分享

MySQL创建数据表并建立主外键关系详解

这篇文章主要介绍了MySQL创建数据表并建立主外键关系详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
收藏 0 赞 0 分享

MySQL表中添加时间戳的几种方法

这篇文章主要介绍了MySQL表中添加时间戳的几种方法,有张表的数据需要用同步工具同步至其他库,需要 update_time 时间戳字段 来做增量同步,需要的朋友可以参考下
收藏 0 赞 0 分享

MySQL如何实现负载均衡功能

这篇文章主要介绍了MySQL如何实现负载均衡功能,学习过数据库的朋友们都会知道MySQL,那么如何在MySQL下实现负载均衡功能呢?本文就将为大家细致地介绍一下
收藏 0 赞 0 分享

mysql server 5.5连接不上的解决方法

这篇文章主要为大家详细介绍了mysql server 5.5连接不上的解决方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享
查看更多