Home  >  Article  >  Database  >  Detailed explanation of MySQL backup and recovery

Detailed explanation of MySQL backup and recovery

青灯夜游
青灯夜游forward
2019-11-29 16:21:512192browse

Detailed explanation of MySQL backup and recovery

1. MySQL full backup and recovery

The main purpose of backup is disaster recovery, and backup can also be used to test applications , rollback data modification, query historical data, audit, etc.

1. The importance of data backup

The value of data in an enterprise is crucial, and data guarantees the normal operation of the enterprise's business. Therefore, data security and data reliability are top priorities for operation and maintenance, and any data loss may have serious consequences for the enterprise. Usually the reasons for data loss are as follows:

Program error
Human operation error
Operation error
Disk failure
Disaster (fire, earthquake) and theft
3. Common backup methods

2. Database backup types

1. From Physical and logical perspectives:

Database backup can be divided into physical backup and logical backup. Physical backup is a backup of the physical files of the database operating system (such as data files, log files, etc.). This type of backup is suitable for large and important databases that need to be restored quickly if something goes wrong.

Physical backup can be divided into cold backup (offline backup), hot backup (online backup) and warm backup.

  • Cold backup: perform backup operations when the database is closed;
  • Hot backup: perform backup operations when the database is running. The backup method relies on the log file of the database;

  • Warm backup: Backup when the database locks the table (cannot be written, but can be read);

Logical backup It is a backup of the logical components of the database (such as tables and other database objects), and is expressed as information about the logical database structure (create database, create table statements) and content (insert statements or delimited text files). This type of backup is used for smaller amounts of data where the data values ​​or table structures can be edited, or the data can be recreated on a different machine architecture.

2. From the perspective of database backup strategy:

From the perspective of database backup strategy, database backup can Divided into full backup, differential backup and incremental backup. Among them, full backup is the basis for differential and incremental backup.

  • Full backup: A complete backup of the data every time, that is, a backup of the entire database. The backup and recovery operations are very simple, but there is a lot of duplication of data, which takes up a lot of disk space and the backup time is also very long.

  • Differential backup: Back up all files that have been modified since the last full backup. The backup time point is from the last full backup, and the backup data will become larger and larger. When restoring data, only the last full backup and the most recent differential backup need to be restored.

  • Incremental backup: Only files that have been modified after the last full backup or incremental backup will be backed up, with the time of the last full backup or the last incremental backup as the time point. , only backs up the data changes in between, so the amount of data backed up is small, the space is small, and the backup speed is fast. However, when restoring, all increments from the last full backup to the last incremental backup are needed. Restore in sequence. Once the data in the middle is damaged, data will be lost.

3. Common backup methods

MySQL database can be backed up in many ways, such as directly packaging the database File (physical cold backup), special backup tool (mysqldump), binary log incremental backup, third-party tool backup, etc.

1. Physical cold backup

#Physical cold backup requires the database to be closed to ensure the integrity of the database. . Physical cold backup is generally used for non-core services. This type of business generally allows interruption. The characteristic of physical cold backup is that it is fast and the recovery is the simplest.

2. Special backup tools mysqldump or mysqlhotcopy

Both the mysqldump program and mysqlhotcopy can be used for backup. mysqqldump is a commonly used logical backup program on the client side that can generate a set of SQL statements that are executed to reproduce the original database object definitions and table data. It can dump one to multiple MySQL databases, back them up or transfer them to a remote SQL server. mysqldump is more versatile as it can back up a variety of tables. mysqlhotcopy only works with certain storage engines.

3. Incremental backup by enabling binary log

MySQL supports incremental backup, and binary log must be enabled when performing incremental backup. Binary log files provide users with a copy of the information needed to recover database changes made after the backup point was performed. If you perform an incremental backup (containing data modifications that occurred since the last full or incremental backup), you need to refresh the binary log.

4. Full database backup operation

1. Preparation before backup

[root@centos01 ~]# mysqladmin -u root password  <!--mysql数据库设置密码-->
New password:             <!--输入密码-->
Confirm new password:        <!--确认密码-->
[root@centos01 ~]# mysql -uroot -ppwd@123    <!--登录MySQL数据库-->
mysql> create database benet;        <!--创建benet数据库-->
mysql> use benet;             <!--切换到benet数据库创建表-->
mysql> create table 一班学生成绩 (姓名 char(3),班级 char(5),学号 char(8),语文 char(3),
数学char(3),英语 char(3),理综 char(3), primary key (学号));  
<!--创建表,表名字为一班学生成绩,第一列名字是姓名,第二列名字为班级,第三列名字
为学号,第四列名字为语文,第五列名字为数学,第六列名字为英语,第七列名字为理综-->
mysql> insert into 一班学生成绩 value ('张三','一班','20170822','110','105','92','235');  
                   <!--表中插入数据-->
mysql>  insert into 一班学生成绩 value ('李四','一班','20170820','95','115','110','260');  
                   <!--表中插入数据-->
mysql> insert into 一班学生成绩 value ('王五','一班','20170818','95','103','108','270');  
                   <!--表中插入数据-->
mysql> insert into 一班学生成绩 value ('赵六','一班','20170816','100','109','112','265'); 
                   <!--表中插入数据-->
mysql> select * from benet.一班学生成绩;   <!--查看一班学生成绩表中所有数据-->

Detailed explanation of MySQL backup and recovery

2. Physical cold backup and recovery

Physical cold backup generally uses the tar command to directly package the database folder. Before performing a backup, you need to use the "systemctl stop mysqld" command to shut down the mysql service.

1) Back up the database

Create a /bak directory as the backup data storage path, and use tar to create the backup file. The backup of the entire database folder is a full backup.

[root@centos01 ~]# systemctl stop mysqld  <!--停止mysql服务-->
[root@centos01 ~]mkdir /bak/   <!--创建存储备份目录-->
[root@centos01 ~]# tar zcf /bak/mysql_all-$(date +%F).mysql.gz /usr/local/mysql/data/    
                 <!--直接tar打包数据库文件-->
[root@centos01 ~]# ls /bak/     <!--查看备份的数据-->
-rw-r--r-- 1 root root 766598 10月 31 03:57 /bak/mysql_all-2019-10-31.mysql.gz

2) Restore the database

[root@centos01 ~]mkdir test  <!--创建恢复数据目录-->
[root@centos01 ~]# tar zxvf /bak/mysql_all-2019-10-31.mysql.gz  -C ./test/   
                <!--解压缩备份数据到恢复目录-->
[root@centos01 data]# cd /usr/local/mysql/data/  <!--进入数据原始位置-->
[root@centos01 data]# rm -rf ./*  <!--删除数据-->
[root@centos01 ~]# cd ./test/usr/local/mysql/data/  <!--切换到恢复目录-->
[root@centos01 date]#mv ./* /usr/local/mysql/data/    <!--将恢复目录数据恢复到原始位置-->
[root@centos01 ~]# systemctl start mysqld  <!--启动mysql服务-->

3. Mysqldump backup and recovery

Through mysqldump The command can export the specified library, table or all libraries as SQL scripts, so that the command can be used on different versions of MySQL servers.

1) Back up and restore all databases

[root@centos01 ~]# mysqldump -uroot -ppwd@123 --opt --all-databases > ./test/benet_databases.sql     <!--备份所有库,opt选项是优化执行速度-->
[root@centos01 ~]# mysql -uroot -p     <!--登录数据库-->
Enter password:          <!--数据密码-->
mysql> show databases;         <!--查看所有数据库-->
+--------------------+
| Database           |
+--------------------+
| information_schema |
| benet              |
| mysql              |
| performance_schema |
| test               |
+--------------------+
mysql> drop database benet;  <!--删除benet数据库-->
mysql> show databases;      <!--查看数据库是否删除-->
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
[root@centos01 ~]# mysql -u root -p 
mysql> show databases;     <!--查看数据库是否恢复-->
+--------------------+
| Database           |
+--------------------+
| information_schema |
| benet              |
| mysql              |
| performance_schema |
| test               |
+--------------------+
mysql> source ./test/benet_databases.sql 
             <!--也可以通过这种方法恢复误删除的数据库-->

2) Back up and restore tables in the database

[root@centos01 ~]# mysqldump -uroo t -ppwd@123 benet 一班学生成绩 > ./test/benet_一班学生成绩.sql   
                         <!--备份数据库下的表-->
[root@centos01 ~]# mysql -uroot -p       <!--登录数据库-->
Enter password:        <!--输入密码-->
mysql> use benet;      <!--切换到benet数据库-->
mysql> drop table 一班学生成绩;      <!--删除一班学生成绩表-->
mysql> show tables;        <!--查看表是否删除--> 
Empty set (0.00 sec)
[root@centos01 ~]# mysql -uroot -p benet 
[root@centos01 ~]# mysql -uroot -p    <!--登录数据库-->
Enter password:           <!--输入密码-->
mysql> use benet;         <!--切换到benet数据库-->
Database changed
mysql> show tables;    <!--查看误删除的表是否恢复-->
+--------------------+
| Tables_in_benet    |
+--------------------+
| 一班学生成绩       |
+--------------------+
1 row in set (0.00 sec)

5. MySQL Incremental Backup and Recovery

Use mysqldump to perform a full backup. There are duplicate data in the backed up data, and the backup time and recovery time are too long. Incremental backup is to back up files or content that have been added or changed since the last backup.

1. Characteristics of MySQL incremental backup

Different from full backup, incremental backup does not have duplicate data, the backup volume is not large, and the time is Short; but its recovery is troublesome. It requires the last full backup and all incremental backups after the full backup to restore, and all incremental backups need to be restored one by one. Incremental backup can be achieved indirectly through the binary log provided by MySQL.

2. MySQL incremental backup and recovery

The binary log saves all operations that update or may update the database. The binary log starts recording after starting the MySQL server, and creates a new log file when the file reaches the maximum value set by the binary log or receives the flush logs command, generates a sequence of binary files, and saves these logs to secure storage in a timely manner. location, you can complete incremental backup for a period of time.
To perform incremental backup of MySQL, you must first enable the binary log function. The implementation method of enabling the binary log function of MySQL is as follows:

[root@centos01 ~]# vim /etc/my.cnf       <!--进入MySQL配置文件-->
.......    <!--此处省略部分内容-->
log-bin=mysql-bin      <!--开启二进制日志功能-->
[root@centos01 ~]# systemctl restart mysqld   <!--重启MySQL服务-->
[root@centos01 ~]# ls -l /usr/local/mysql/data/
......             <!--此处省略部分内容-->
-rw-rw---- 1 mysql mysql    27299 10月 31 00:00 mysql-bin.000001
-rw-rw---- 1 mysql mysql  1031892 10月 31 00:00 mysql-bin.000002
-rw-rw---- 1 mysql mysql     1574 10月 31 14:13 mysql-bin.000003
-rw-rw---- 1 mysql mysql   507535 11月  1 09:37 mysql-bin.000004
-rw-rw---- 1 mysql mysql   507229 11月  1 09:40 mysql-bin.000005
-rw-rw---- 1 mysql mysql       95 11月  1 09:37 mysql-bin.index
drwx------ 2 mysql mysql     4096 10月 31 00:00 performance_schema
drwxr-xr-x 2 mysql mysql       20 10月 30 23:56 test

1) Incremental backup

[root@centos01 ~]# mysqladmin -uroot -ppwd@123 flush-logs  <!--刷新二进制日志-->
[root@centos01 ~]# ls -l /usr/local/mysql/data/     <!--查看二进制日志文件-->
......   <!--此处省略部分内容-->
-rw-rw---- 1 mysql mysql    27299 10月 31 00:00 mysql-bin.000001
-rw-rw---- 1 mysql mysql  1031892 10月 31 00:00 mysql-bin.000002
-rw-rw---- 1 mysql mysql     1574 10月 31 14:13 mysql-bin.000003
-rw-rw---- 1 mysql mysql   507535 11月  1 09:37 mysql-bin.000004
-rw-rw---- 1 mysql mysql   507272 11月  1 09:49 mysql-bin.000005
-rw-rw---- 1 mysql mysql      107 11月  1 09:49 mysql-bin.000006
-rw-rw---- 1 mysql mysql      114 11月  1 09:49 mysql-bin.index
drwx------ 2 mysql mysql     4096 10月 31 00:00 performance_schema
drwxr-xr-x 2 mysql mysql       20 10月 30 23:56 test
[root@centos01 ~]# mysql -uroot -ppwd@123  <!--登录mysql数据库-->
mysql> use benet;           <!--切换到benet数据库-->
mysql> insert into 一班学生成绩 value ('李宁','二班','20170824','92','98','105','235');            
                    <!--录入新的数据-->
Query OK, 1 row affected (0.01 sec)
mysql> insert into 一班学生成绩 value ('陈铭','二班','20170826','111','107','96','204');           
                    <!--录入新的数据-->
Query OK, 1 row affected (0.00 sec)
mysql> select *from 一班学生成绩;    <!--查看新数据是否录入-->
+--------+--------+----------+--------+--------+--------+--------+
| 姓名   | 班级   | 学号     | 语文   | 数学   | 英语   | 理综   |
+--------+--------+----------+--------+--------+--------+--------+
| 赵六   | 一班   | 20170816 | 100    | 109    | 112    | 265    |
| 王五   | 一班   | 20170818 | 95     | 103    | 108    | 270    |
| 李四   | 一班   | 20170820 | 95     | 115    | 110    | 260    |
| 张三   | 一班   | 20170822 | 110    | 105    | 92     | 235    |
| 李宁   | 二班   | 20170824 | 92     | 98     | 105    | 235    |
| 陈铭   | 二班   | 20170826 | 111    | 107    | 96     | 204    |
+--------+--------+----------+--------+--------+--------+--------+
6 rows in set (0.00 sec)
[root@centos01 ~]# mysqladmin -uroot -ppwd@123 flush-logs  
                          <!--刷新二进制日志-->
[root@centos01 ~]# ls -l /usr/local/mysql/data/    
                               <!--查看二进制日志文件-->
......          <!--此处省略部分内容-->
-rw-rw---- 1 mysql mysql    27299 10月 31 00:00 mysql-bin.000001
-rw-rw---- 1 mysql mysql  1031892 10月 31 00:00 mysql-bin.000002
-rw-rw---- 1 mysql mysql     1574 10月 31 14:13 mysql-bin.000003
-rw-rw---- 1 mysql mysql   507535 11月  1 09:37 mysql-bin.000004
-rw-rw---- 1 mysql mysql   507272 11月  1 09:49 mysql-bin.000005
-rw-rw---- 1 mysql mysql      649 11月  1 09:58 mysql-bin.000006
-rw-rw---- 1 mysql mysql      107 11月  1 09:58 mysql-bin.000007
-rw-rw---- 1 mysql mysql      133 11月  1 09:58 mysql-bin.index
drwx------ 2 mysql mysql     4096 10月 31 00:00 performance_schema
drwxr-xr-x 2 mysql mysql       20 10月 30 23:56 test
[root@centos01 ~]# cp /usr/local/mysql/data/mysql-bin.000006 /root/test/   
                            <!--复制二进制日志-->

2) Simulate the accidental deletion of a class of student performance tables

[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'drop table benet.一班学生成绩;'       
                    <!--删除一班学生成绩表-->
[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'select * from benet.一班学生成绩;'   
                      <!--查看表是否删除-->
ERROR 1146 (42S02) at line 1: Table 'benet.一班学生成绩' doesn't exist

3) Restore the accidentally deleted table

[root@centos01 ~]# mysql -uroot -ppwd@123 
[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'select * from benet.一班学生成绩;'        
                        <!--查看完全备份数据是否恢复-->
+--------+--------+----------+--------+--------+--------+--------+
| 姓名   | 班级   | 学号     | 语文   | 数学   | 英语   | 理综   |
+--------+--------+----------+--------+--------+--------+--------+
| 赵六   | 一班   | 20170816 | 100    | 109    | 112    | 265    |
| 王五   | 一班   | 20170818 | 95     | 103    | 108    | 270    |
| 李四   | 一班   | 20170820 | 95     | 115    | 110    | 260    |
| 张三   | 一班   | 20170822 | 110    | 105    | 92     | 235    |
+--------+--------+----------+--------+--------+--------+--------+
[root@centos01 ~]# mysqlbinlog --no-defaults /root/test/mysql-bin.000006 |mysql -u root -p 
                   <!--恢复增量备份-->
Enter password:       <!--输入密码-->
[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'select * from benet.一班学生成绩;'      
                     <!--查看增量恢复数据是否恢复-->
+--------+--------+----------+--------+--------+--------+--------+
| 姓名   | 班级   | 学号     | 语文   | 数学   | 英语   | 理综   |
+--------+--------+----------+--------+--------+--------+--------+
| 赵六   | 一班   | 20170816 | 100    | 109    | 112    | 265    |
| 王五   | 一班   | 20170818 | 95     | 103    | 108    | 270    |
| 李四   | 一班   | 20170820 | 95     | 115    | 110    | 260    |
| 张三   | 一班   | 20170822 | 110    | 105    | 92     | 235    |
| 李宁   | 二班   | 20170824 | 92     | 98     | 105    | 235    |
| 陈铭   | 二班   | 20170826 | 111    | 107    | 96     | 204    |
+--------+--------+----------+--------+--------+--------+--------+

3. Position-based recovery

[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'drop table benet.一班学生成绩;'   
                <!--删除一班学生成绩表-->
[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'select * from benet.一班学生成绩;'  
                 <!--查看表是否删除-->
ERROR 1146 (42S02) at line 1: Table 'benet.一班学生成绩' doesn't exist
[root@centos01 ~]# mysql -uroot -ppwd@123 
[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'select * from benet.一班学生成绩;'     
               <!--查看完全备份是否恢复-->
+--------+--------+----------+--------+--------+--------+--------+
| 姓名   | 班级   | 学号     | 语文   | 数学   | 英语   | 理综   |
+--------+--------+----------+--------+--------+--------+--------+
| 赵六   | 一班   | 20170816 | 100    | 109    | 112    | 265    |
| 王五   | 一班   | 20170818 | 95     | 103    | 108    | 270    |
| 李四   | 一班   | 20170820 | 95     | 115    | 110    | 260    |
| 张三   | 一班   | 20170822 | 110    | 105    | 92     | 235    |
+--------+--------+----------+--------+--------+--------+--------+
[root@centos01 ~]# mysqlbinlog --no-defaults /root/test/mysql-bin.000006       
                <!--查看二进制日志文件确认恢复的位置或时间点-->
......         <!--此处省略部分内容-->
# at 176                  <!--at就是我们称之为操作ID,下面紧跟的是时间标记-->
#191101  9:55:33 server id 1  end_log_pos 329   Query   thread_id=9 exec_time=0 error_code=0
use benet/*!*/;
SET TIMESTAMP=1572573333/*!*/;
insert into 一班学生成绩 value ('李宁','二班','20170824','92','98','105','235')
/*!*/;
# at 329
#191101  9:55:33 server id 1  end_log_pos 356   Xid = 278
COMMIT/*!*/;
# at 356
#191101  9:55:43 server id 1  end_log_pos 425   Query   thread_id=9 exec_time=0 error_code=0
SET TIMESTAMP=1572573343/*!*/;
BEGIN
/*!*/;
# at 425       <!--at就是我们称之为操作ID,下面紧跟的是时间标记-->
#191101  9:55:43 server id 1  end_log_pos 579   Query   thread_id=9 exec_time=0 error_code=0
SET TIMESTAMP=1572573343/*!*/;
insert into 一班学生成绩 value ('陈铭','二班','20170826','111','107','96','204')
/*!*/;
[root@centos01 ~]# mysqlbinlog --no-defaults --stop-position='425' /root/test/mysql-bin.000006 |mysql -uroot -p       <!--基于ID恢复增量备份-->
Enter password:       <!--输入密码-->
[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'select * from benet.一班学生成绩;'    
               <!--查看数据是否恢复-->
+--------+--------+----------+--------+--------+--------+--------+
| 姓名   | 班级   | 学号     | 语文   | 数学   | 英语   | 理综   |
+--------+--------+----------+--------+--------+--------+--------+
| 赵六   | 一班   | 20170816 | 100    | 109    | 112    | 265    |
| 王五   | 一班   | 20170818 | 95     | 103    | 108    | 270    |
| 李四   | 一班   | 20170820 | 95     | 115    | 110    | 260    |
| 张三   | 一班   | 20170822 | 110    | 105    | 92     | 235    |
| 李宁   | 二班   | 20170824 | 92     | 98     | 105    | 235    |
+--------+--------+----------+--------+--------+--------+--------+

The "--stop-position" in the above command specifies the stop position. If only To restore the information of "Chen Ming" and skip the information recovery of "Li Ning", you can use the "--start-position" option to specify the position to start data recovery. The data recovered at this time starts from the specified position until the end of the binary log file.

[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'drop table benet.一班学生成绩;'    
                   <!--删除一班学生成绩表-->
[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'select * from benet.一班学生成绩;'  
                  <!--查看表是否删除-->
ERROR 1146 (42S02) at line 1: Table 'benet.一班学生成绩' doesn't exist
[root@centos01 ~]# mysql -uroot -ppwd@123 
[root@centos01 ~]# mysqlbinlog --no-defaults --start-position='425' /root/test/mysql-bin.000006 |mysql -uroot -p       <!--基于ID恢复增量备份-->
Enter password:        <!--输入密码-->
[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'select * from benet.一班学生成绩;'    
                 <!--查看数据是否恢复-->
+--------+--------+----------+--------+--------+--------+--------+
| 姓名   | 班级   | 学号     | 语文   | 数学   | 英语   | 理综   |
+--------+--------+----------+--------+--------+--------+--------+
| 赵六   | 一班   | 20170816 | 100    | 109    | 112    | 265    |
| 王五   | 一班   | 20170818 | 95     | 103    | 108    | 270    |
| 李四   | 一班   | 20170820 | 95     | 115    | 110    | 260    |
| 张三   | 一班   | 20170822 | 110    | 105    | 92     | 235    |
| 陈铭   | 二班   | 20170826 | 111    | 107    | 96     | 204    |
+--------+--------+----------+--------+--------+--------+--------+

#4. Recovery based on point in time

##The option used to recover data based on point in time is "-- stop-datetime", the specified time is also obtained by querying the binary log. By performing the following operations, you can only restore the data before 9:55:43, that is, the information of "Chen Ming" will not be restored.

[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'drop table benet.一班学生成绩;' 
                      <!--删除一班学生成绩表-->
[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'select * from benet.一班学生成绩;'  
                 <!--查看表是否删除-->
ERROR 1146 (42S02) at line 1: Table 'benet.一班学生成绩' doesn't exist
[root@centos01 ~]# mysql -uroot -ppwd@123 
[root@centos01 ~]# mysqlbinlog --no-defaults --stop-datetime='2019-11-01  9:55:43' /root/test/mysql-bin.000006 |mysql -uroot -p     
                         <!--基于时间点恢复增量备份-->
Enter password:       <!--输入密码-->
[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'select * from benet.一班学生成绩;'    
                           <!--查看数据是否恢复-->
+--------+--------+----------+--------+--------+--------+--------+
| 姓名   | 班级   | 学号     | 语文   | 数学   | 英语   | 理综   |
+--------+--------+----------+--------+--------+--------+--------+
| 赵六   | 一班   | 20170816 | 100    | 109    | 112    | 265    |
| 王五   | 一班   | 20170818 | 95     | 103    | 108    | 270    |
| 李四   | 一班   | 20170820 | 95     | 115    | 110    | 260    |
| 张三   | 一班   | 20170822 | 110    | 105    | 92     | 235    |
| 李宁   | 二班   | 20170824 | 92     | 98     | 105    | 235    |
+--------+--------+----------+--------+--------+--------+--------+

Perform the following operations to restore only the information of "Chen Ming" and skip the information recovery of "Li Ning"

[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'drop table benet.一班学生成绩;'   
                      <!--删除一班学生成绩表-->
[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'select * from benet.一班学生成绩;'    
                 <!--查看表是否删除-->
ERROR 1146 (42S02) at line 1: Table 'benet.一班学生成绩' doesn't exist
[root@centos01 ~]# mysql -uroot -ppwd@123 
[root@centos01 ~]# mysqlbinlog --no-defaults --start-datetime='2019-11-01 9:55:43'
/root/test/mysql-bin.000006 |mysql -uroot -p      
                      <!--基于时间恢复增量备份-->
Enter password:        <!--输入密码-->
[root@centos01 ~]# mysql -uroot -ppwd@123 -e 'select * from benet.一班学生成绩;'    
                       <!--查看数据是否恢复-->
+--------+--------+----------+--------+--------+--------+--------+
| 姓名   | 班级   | 学号     | 语文   | 数学   | 英语   | 理综   |
+--------+--------+----------+--------+--------+--------+--------+
| 赵六   | 一班   | 20170816 | 100    | 109    | 112    | 265    |
| 王五   | 一班   | 20170818 | 95     | 103    | 108    | 270    |
| 李四   | 一班   | 20170820 | 95     | 115    | 110    | 260    |
| 张三   | 一班   | 20170822 | 110    | 105    | 92     | 235    |
| 陈铭   | 二班   | 20170826 | 111    | 107    | 96     | 204    |
+--------+--------+----------+--------+--------+--------+--------+
—————— — This article ends, thank you for reading——————

Recommended learning:

MySQL tutorial

The above is the detailed content of Detailed explanation of MySQL backup and recovery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete