当前位置:网站首页>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
边栏推荐
- Expression related to month, year and day in SVG
- STO With Billing 跨公司库存转储退货
- A programmer who works four hours a day
- 关于U盘数据提示RAW,需要格式化,数据恢复笔记
- Zhuang understand's TA notes (VI) < fakeenvreflect & rust, rust effect >
- Protobuf use
- Suggestions on university learning route planning
- Shapley Explanation Networks
- 内网渗透系列:内网隧道之dns2tcp
- 大学学习路线规划建议贴
猜你喜欢

SAP TR手动导入系统操作手册
![[unity VFX] Introduction notes of VFX special effects - spark production](/img/bb/a6c637d025dfb8877e6b85e7f39d6b.png)
[unity VFX] Introduction notes of VFX special effects - spark production

Robust and Efficient Quadrotor Trajectory Generation for Fast Autonomous Flight

Scrapy modifies the time in the statistics at the end of the crawler as the current system time

Houdini地形与流体解算(模拟泥石流)

How does Apache Hudi accelerate traditional batch mode?

Common markdown grammar learning

C # control the camera, rotate and drag the observation script (similar to scenes observation mode)

VBA appelle SAP RFC pour réaliser la lecture et l'écriture des données

平面定义-平面方程
随机推荐
Unity C single case mode learning review notes
SAP Query增强开发介绍
CTF-MISC总结
Teach-Repeat-Replan: A Complete and Robust System for Aggressive Flight in Complex Environments
Houdini > rigid body, rigid body breaking RBD
内网渗透系列:内网隧道之icmptunnel(DhavalKapil师傅的)
庄懂的TA笔记(零)<铺垫与学习方法>
Nodejs (four) character reading
C # use laida criterion (3) σ Criteria) reject abnormal data (.Net reject singular values in a group of data)
读取修改resource文件夹下的json文件
ABAP ALV显示金额与导出金额不一致
VBA調用SAP RFC實現數據讀取&寫入
Simplify exporting to SVG data files and all images in SVG folder
Read and modify the JSON file under the resource folder
SQL sorts string numbers
Understanding the Role of Individual Units in a Deep Neural Networks(了解各个卷积核在神经网络中的作用)
[unity VFX] Introduction notes of VFX special effects - spark production
IDEA快捷键
SampleCameraFilter
C reads the registry