单库单表备份,恢复单表数据

create database olddog;
use olddog;
create table w1(id int);
insert into w1 values(1),(2),(3);
commit;

单库单表备份数据

mysql> select concat("mysqldump -uroot -p123456 ",table_schema," ",table_name," --master-data=2 --singlegle-transaction   -R -E --triggers>/backup/",table_schema,"_",table_name,".sql") from information_schema.tables where table_schema not in ('sys','mysql','information_schema','performance_schema') into outfile '/tmp/out.sql';
cat /tmp/out.sql

单库单表备份,恢复单表数据_第1张图片

[root@db01]#sh /tmp/out.sql

单库单表备份,恢复单表数据_第2张图片

单库单表全备

单库单表备份,恢复单表数据_第3张图片

备份后的操作

insert into w1 values(111),(222),(333);
 insert into w1 values(11),(22),(33);
commit;

单库单表备份,恢复单表数据_第4张图片

删库

drop  table w1;

恢复数据

1截取二进制日志

 vim /backup/olddog_w1.sql

单库单表备份,恢复单表数据_第5张图片

mysql> show master status ;

单库单表备份,恢复单表数据_第6张图片

mysql> show binlog events in "mysql-bin.000004";

单库单表备份,恢复单表数据_第7张图片

 mysqlbinlog --skip-gtids --include-gtids="ee724332-9432-11ea-9a9d-000c29259def:9-10" /data/mysql/log/binlog/mysql-bin.000004 > /b.sql
mysql> set sql_log_bin=0;

2先恢复单库单表备份数据

mysql> source /backup/olddog_w1.sql

3再恢复二进制日志数据

source /b.sql

单库单表备份,恢复单表数据_第8张图片

你可能感兴趣的:(mysql)