如何用mysqldump进行全量和时间点备份
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和s slave语句。—include-master-host-port包含主库的连接信息。
必须记住一点,即使有—single-transaction语句,—dump-slave也会暂停mysql同步,也就是备份库的数据是落后于主库的,所以一般自动化脚本在备份的时候会先摘除备份库。
This option causes mysqldump to s the slave SQL thread before the dump and restart it again after.
3如何进行时间点恢复
没有实战过,基于最近的一次全量备份进行恢复,然后将后续的binlog文件导入(如果这些文件还在的话),所以副库最好也备份binlog语句。
如果数据被误删除了,将备份点(—flush-logs发挥作用了)到今天凌晨的binlog语句导入进来,或者找到安全的binlog位置点进行恢复。至于如何跳过“危险语句”是比较难控制的。
以上就是如何用mysqldump进行全量和时间点备份的详细内容,更多关于mysqldump进行全量和时间点备份的资料请关注狼蚁SEO其它相关文章!
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指