当前位置:网站首页>Mysql database backup and recovery under Linux (full + incremental)
Mysql database backup and recovery under Linux (full + incremental)
2022-04-23 07:57:00 【Willie Y】
To simulate mysql Backup and recovery of database , This document will introduce the creation of database 、 Table creation 、 Insert data into 、 Full database backup 、 Log segmentation 、 Data recovery, etc
1、 Database creation
Log in to the database :
[root@zeshintax02 ~]# mysql -uroot –p
Create database tb1, surface ttab01:
mysql> create database tb1 default charset utf8mb4;
Query OK, 1 row affected (0.01 sec)
mysql> use tb1
Database changed
mysql> create table ttable01(
-> id int auto_increment primary key,
-> name varchar(15)
-> )engine = InnoDB;
Query OK, 0 rows affected (0.02 sec)
2、 insert data :
3、 Use mysqldump Full backup data :
【 notes 】: Usually, when using the full backup command, you need to add parameters :
Mysqldump -uroot -p --single-transaction --master-data=2 --routines --flush-logs -B --all-databases > fullbackupfile.sql
Parameters --single-transaction、 --master-data=2 Represents a consistent backup , Generally used together , Not only .--routines Backup function trigger 、--flush-logs Refresh the log before backup ( Ensure complete data backup , If the database has binary logs , You do not need to use this parameter and consistency parameter --single-transaction、 --master-data=2) Parameters -B: The biggest feature is the addition of the library , There is no need to create a library during data recovery .
4、 Continue inserting data :
5、 Use mysqlbinlog Check the log
mysqlbinlog You can view the contents of the database binary log file , There are statements for inserting data . view log file :
6、mysqladmin Split log
To see the changes in the database , Use mysqladmin Options in command flush-logs Split the newly generated binary file of the database , In this way, after writing new data , The new binary file corresponds to the changed content of the database .
Check whether the binary log file is added :
Insert a new data ;
Use mysqlbinlog Commands can be viewed mysql-bin.000003 Contents of database binary log file , In it, the newly inserted data statement is saved :
Reuse mysqladmin Options in flush-logs Split the database binary log file :
Because the database has not been added, deleted or modified, new data , Therefore, the binary log file after segmentation has no relevant content .
Insert a piece of data :
Then check the binary log file :
The new binary log file holds the newly inserted content , Above .
Two 、 Restore data
1、 Partial data recovery after full backup
(1) Analog data loss : Use delete Delete the two pieces of data inserted
You can see that there are two pieces of data missing in the table .
(2) Use the binary log file generated before to recover the data ,( Need to pay attention to recovery order , The earliest data needs to recover the corresponding binary file first ):
You can view a piece of data that has been successfully restored , Continue to restore another :
This completes the recovery of two pieces of data .
2、 Data recovery after full backup
(1)、 View data :
After log segmentation , The list of binary files is as follows :
Insert a piece of data :
Do log segmentation , And look at the resulting new binary :
Insert a piece of data again :
Check the corresponding binary file , It is found that the written data has been recorded :
Delete table , Then use the full set + Incremental backup to restore data :
Now data recovery :
A、 Full data recovery first :
You can find that the table is restored , View table data :
The table saves the data during full standby , Then restore the incremental log .
B、 Incremental data recovery , Until the last file :
【 notes 】: When restoring incremental logs , In case of an error, you must solve it before you can restore the next file , Otherwise, the data may be incomplete .
版权声明
本文为[Willie Y]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230628041450.html
边栏推荐
- Houdini > rigid body, rigid body breaking RBD
- BUUCTF MISC刷题
- SAP Query增强开发介绍
- 读书笔记
- 第五章 投资性房地产
- Post of experience in preparation for guarantee and research -- the 18th (2021) Central South planning department promoted the exemption to Zhejiang University Institute of Technology
- Apache Hudi 如何加速传统的批处理模式?
- Unity 获取一个资源被那些资源引用
- Zhuang understand's TA notes (VI) < fakeenvreflect & rust, rust effect >
- Unity获取真实地理地图应用Terrain笔记
猜你喜欢
MySQL8. 0 installation / uninstallation tutorial [window10 version]
Shapley Explanation Networks
内网渗透系列:内网隧道之icmptunnel(DhavalKapil师傅的)
内网渗透系列:内网隧道之dnscat2
Use of command line parameter passing library argparse
Understanding the Role of Individual Units in a Deep Neural Networks(了解各个卷积核在神经网络中的作用)
Protobuf 使用
内网渗透系列:内网隧道之icmpsh
内网渗透系列:内网隧道之icmptunnel(jamesbarlow师傅的)
内网渗透系列:内网隧道之pingtunnel
随机推荐
内网渗透系列:内网隧道之dnscat2
內網滲透系列:內網隧道之icmpsh
Plane definition - plane equation
索引被锁数据无法写入ES问题处理
读书笔记
Houdini>建筑道路可变,学习过程笔记
关于U盘数据提示RAW,需要格式化,数据恢复笔记
大学学习路线规划建议贴
SampleCameraFilter
Idea shortcut
Understanding the role of individual units in a deep neural networks
Use of command line parameter passing library argparse
攻防世界MISC刷题1-50
Houdini > variable building roads, learning process notes
Understanding the Role of Individual Units in a Deep Neural Networks(了解各个卷积核在神经网络中的作用)
Complete color conversion formulas and conversion tables (31 kinds)
Unity gets a resource that is referenced by those resources
Houdini地形与流体解算(模拟泥石流)
CTF攻防世界刷题51-
Complete learning from scratch, machine learning and deep learning, including theory and code implementation, mainly using scikit and mxnet, and some practices (on kaggle)