MySQL-备份类型day10

备份类型

1.冷备 cold backup

业务停止或数据库关闭,进行备份,业务影响最大。

2.温备 warm backup

锁表备份,只读备份,阻塞所有的变更的操作,只能读。

3.热备 hot backup

不锁表备份,只能针对事务型引擎的表(例如:InnoDB)业务的影响最小。

4.备份工具

4.1 mysqldump MDP

        逻辑备份工具
        备份出来都是SQL语句 
        可读性较强
        便于二次处理
        文本格式,压缩比高
        自带工具

劣势:相对较慢,从磁盘调取数据--->内存--->转换成SQL---->xx.sql
不能做增量

Xtrabackup(percona) XBK,PBX

MySQL Enterpise Backup ,MEB 企业版
物理备份工具,备份的数据文件(类似cp)
优势:备份速度快
支持热备
自带了增量备份功能。

劣势:
可读性比较差
不便于处理
压缩比低

选择建议:

小于100G :MDP,XBK
100G-1T :XBK
超过TB级别:XBK,MDP

5.备份策略

备份方式:
全备:全库备份,备份所有数据
增量:备份变化的数据
逻辑备份=mysqldump+binlog
物理备份=XBK_full+xtrabcakup_incr_binlog或者xtrabackup_full+binlog
备份周期:
根据数据量设计备份周期
比如:周日全备,周1-周6增量

6.mysqldump逻辑备份工具使用

6.1 客户端通用的参数

-u
-p
-h
-P
-S

6.2基础备份参数

-A --all-databases 全库备份

[root@db01 ~]# mysqldump -uroot -p123456 -A > /backup/full.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events. 
[root@db01 ~]# 

-B 单库或多库备份
例子:只备份world和test两个库

[root@db01 ~]# mysqldump -uroot -p123456 -B world test > /backup/db.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events. 
[root@db01 ~]# 

单表或多表备份

[root@db01 ~]# mysqldump -uroot -p123456 world city country >/backup/table.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events. 

6.3特殊功能参数

  1. -R --triggers -E 数据库特殊对象备份参数
    -R 存储过程,函数
    --triggers 触发器
    -E 事件

  2. --master-data=2
    1.以注释形式,记录备份时binlog文件名和position号(截取二进制日志的起点)
    2.自动锁表功能,加--single-transaction,可以减少锁表,
    3.--single-transaction
    快照备份,热备。

  3. --set-gtid-purged=OFF(GTID模式独有的参数。)
    作用,去除gtid所有信息,在日常备份恢复时可加。
    做主从复制应用的时候,不能加此参数。

5.--max-allowed-packet=512M
备份例子

mysqldump -uroot -p123 -A --master-data=2 --single-transaction -R -E --triggers --set-gtid-purged=OFF --max-allowed-packet=256M > /backup/full.sql
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值