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

所属分类: 数据库 / Mysql 阅读数: 764
收藏 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进行全量和时间点备份的资料请关注脚本之家其它相关文章!

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

mysql found_row()使用详解

在参考手册中对found_rows函数的描述是: it is desirable to know how many rows the statement would have returned without the LIMIT. 也就是说,它返回值是如果SQL语句没有加LI
收藏 0 赞 0 分享

很全面的MySQL处理重复数据代码

这篇文章主要为大家详细介绍了MySQL处理重复数据的实现代码,如何防止数据表出现重复数据及如何删除数据表中的重复数据,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

图文详解Ubuntu下安装配置Mysql教程

这篇文章主要以图文结合的方式详细为大家介绍了Ubuntu安装配置Mysql的实现步骤,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Ubuntu下mysql安装和操作图文教程

这篇文章主要为大家详细分享了Ubuntu下mysql安装和操作图文教程,喜欢的朋友可以参考一下
收藏 0 赞 0 分享

Linux/UNIX和Window平台上安装Mysql

这篇文章主要为大家详细介绍了Linux/UNIX和Window两个系统上采用命令安装Mysql的方法,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

忘记MySQL的root密码该怎么办

忘记密码总是一件令人头疼的事情,当我们忘记了MySQL的root密码该怎么办?本文给出解决方法,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Mysql存储引擎MyISAM的常见问题(表损坏、无法访问、磁盘空间不足)

这篇文章主要介绍了Mysql存储引擎MyISAM的常见问题,针对表损坏、无法访问、磁盘空间不足等问题进行解决,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

VS2013连接MySQL5.6成功案例一枚

这篇文章主要为大家分享了VS2013连接MySQL5.6成功案例一枚,很有实用性,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Windows下mysql修改root密码的4种方法

这篇文章主要为大家详细介绍了windows下mysql修改root密码的4种方法,大家可以根据的自己的实际情况进行选择,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

mysql Sort aborted: Out of sort memory, consider increasing server sort buffer size的解决方法

这篇文章主要介绍了mysql Sort aborted: Out of sort memory, consider increasing server sort buffer size的解决方法,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多