Free learning recommendation: mysql video tutorial
Article Directory
1. MySQL incremental backup
Incremental backup can reduce the size of backup files on the basis of full backup, thereby speeding up backup and recovery.
1. Incremental backup Concept
1.1 Why use incremental backup
1.2 Characteristics of incremental backup
The meaning of binary logs for backup is as follows:
- The binary log saves all operations that update or may update the database
- The binary log starts recording after starting the MySQL server, and is re-created after the file reaches the size set by max_binlog_size or receives the flush logs command. Log files
- You only need to execute the flush logs method regularly to re-create new logs, generate binary file sequences, and save these logs to a safe place in time to complete the incremental backup of a period of time
2. Incremental backup example
vim /etc/my.cnf...[mysqld]log-bin=mysql-binbinlog_format = MIXED#指定二进制日志(binlog)的记录格式为 MIXEDsystemctl restart mysqld.service#重启服务cd /usr/local/mysql/datals -l /usr/local/mysql/data/mysql-bin.*#查看二进制文件#二进制日志(binlog)有3种不同的记录格式:STATEMENT(基于SQL语句)、ROW(基于行)、MIXED(混合模式)#默认格式是 STATEMENT
mysqldump -uroot -p123123 SCHOOL CLASS01 > /opt/SCHOOL_CLASS01_$(date +%F).sql#对表进行完全备份mysqldump -uroot -p123123 --all-databases SCHOOL > /opt/SCHOOL_$(date +%F).sql#对库进行完全备份crontab -e#也可以使用计划性任务来执行30 3 * * 3 mysqldump -uroot -p123123 SCHOOL CLASS01 > /opt/SCHOOL_CLASS01_$(date +%F).sql30 3 * * 3 mysqldump -uroot -p123123 --all-databases SCHOOL > /opt/SCHOOL_$(date +%F).sql每周三的凌晨 3:00 对数据库和表进行完全备份
ls /usr/local/mysql/datamysqladmin -uroot -p123123 flush-logs
use SCHOOL;insert into CLASS01 values(3,'wangsan','woman','games');insert into CLASS01 values(4,'wangsi','man','runing');select * from CLASS01;
cd /usr/local/mysql/data/lsmysqladmin -uroot -p123123 flush-logs
cp mysql-bin.000002 /opt/#将记录变更的二进制文件02复制至/opt目录下cd /opt/lsmysqlbinlog --no-defaults --base64-output=decode-rows -v /opt/mysql-bin.000002#使用64位编码机制去解码,按行读取详细内容
2. MySQL incremental recovery
1. Incremental recovery scenario
2.丢失完全备份之后更改的数据的恢复步骤
mysql -uroot -p123123use SCHOOL;delete from CLASS1 where id=3;delete from CLASS1 where id=4;#删除插入的两条数据,模拟完全备份后数据丢失的故障select * from CLASS01;#检查quitmysqlbinlog --no-defaults /opt/mysql-bin.000002 | mysql -uroot -p123123#使用二进制文件进行恢复操作mysql -uroot -p123123 -e "select * from SCHOOL.CLASS01;"#检查表内容是否恢复
3.完全备份之后丢失所有数据的恢复步骤
mysql -uroot -p123123use SCHOOL;drop table CLASS01;#直接删除整个表,假设完全备份后所有数据都丢失了quitmysql -uroot -p123123 SCHOOL <p><img src="https://img.php.cn/upload/article/000/000/052/c368a93d80781ae407afafe02a2ac327-11.png" alt="MySQL introduces incremental backup and recovery"><br><img src="https://img.php.cn/upload/article/000/000/052/1481568b3321e7dca79c49d509572b7b-12.png" alt="MySQL introduces incremental backup and recovery"></p><p><strong>4. 基于时间点与位置的恢复</strong></p>
4.1 基于时间点的恢复
#恢复用户“wangsan”的数据,而不恢复“wangsi”mysql -uroot -p123123 -e "truncate table SCHOOL.CLASS01;"mysql -uroot -p123123 -e "select * from SCHOOL.CLASS01;"mysqlbinlog --no-defaults --stop-datetime='2021-02-06 15:58:39' /opt/mysql-bin.000002 |mysql -uroot -p123123mysql -uroot -p123123 -e "select * from SCHOOL.CLASS01;"
#恢复“wangsi”的数据mysqlbinlog --no-defaults --start-datetime='2021-02-06 15:58:39' /opt/mysql-bin.000002 |mysql -uroot -p
4.1 基于位置的操作
mysqlbinlog --no-defaults --stop-position='609' /opt/mysql-bin.000002 | mysql -uroot -p#使用64位编码机制去解码并按行读取二进制文件02(增量备份)的详细内容......略
#仅恢复“1810”之前的数据,即不恢复“wangsi”的数据mysql -uroot -p123123 -e "select * from SCHOOL.CLASS01;"mysql -uroot -p123123 -e "truncate table SCHOOL.CLASS01;"mysql -uroot -p123123 -e "select * from SCHOOL.CLASS01;"mysqlbinlog --no-defaults --stop-position='1810' /opt/mysql-bin.000002 | mysql -uroot -pmysql -uroot -p123123 -e "select * from SCHOOL.CLASS01;"
#仅恢复“wangsi”的数据,跳过“wangsan”的数据恢复,即仅有第四条记录mysql -uroot -p123123 -e "select * from SCHOOL.CLASS01;"mysqlbinlog --no-defaults --start-position='1810' /opt/mysql-bin.000002 | mysql -uroot -p123123mysql -uroot -p123123 -e "select * from SCHOOL.CLASS01;"
5. 指定企业备份策略的思路
相关免费学习推荐:mysql数据库(视频)
The above is the detailed content of MySQL introduces incremental backup and recovery. For more information, please follow other related articles on the PHP Chinese website!