2、数据备份策略:
- 完全备份:完全备份所有数据
- 增量备份:备份上次备份后,所有新产生的数据
- 差异备份:备份完全备份后,所有新产生的数据
- 在工作中常用的是:完全备份+增量备份、完全备份+差异备份
- 物理备份恢复规范:适合线下服务器的数据库备份数据量小的备份,在生产环境下需要将服务停掉再进行备份,否则可能会造成数据备份不全。
- 优点:备份恢复简单
- 缺点:备份和恢复数据均需要停止数据库(若不停止服务也可以,但会导致备份不完全)仅适用于同操作系统恢复数据,备份数据量大,占用内存空间比较大。
3.1、备份数据
[root@mysql01 ~]# systemctl stop mysqld.service [root@mysql01 ~]# cp -r /var/lib/mysql /bakdir/mysql.bak [root@mysql01 ~]# ls /bakdir/ mysql.bak [root@mysql01 ~]# cd /var/lib/mysql [root@mysql01 mysql]# tar -zcvf /bakdir/mysql.tar.gz ./*
3.2、删除数据,模拟数据丢失
[root@mysql01 ~]# rm -rf /var/lib/mysql/*
3.3、恢复数据
[root@mysql01 ~]# cp -r /bakdir/mysql.bak/* /var/lib/mysql/ [root@mysql01 ~]# chown -R mysql:mysql /var/lib/mysql [root@mysql01 ~]# systemctl start mysqld
3.4、登录数据库,检查数据
[root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | jy1 | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec)4、逻辑备份与恢复
使用数据库服务软件自带命令或安装其他软件提供的命令备份和恢复
逻辑备份恢复规范:使用mysql服务提供的备份命令对数据做备份和恢复,适合备份数据量少的数据。!!!数据库服务必须是运行状态!!!
4.1、创建存储备份文件的目录
[root@mysql01 ~]# mkdir /bakdir1
4.2、备份数据
对一张表进行备份时书写的格式:库名 表名
[root@mysql01 ~]# mysqldump -uroot -pJY1987...zy2011 jy1 zy1 > /bakdir1/jy1_zy1.sql mysqldump: [Warning] Using a password on the command line interface can be insecure. [root@mysql01 ~]# ls /bakdir1/ jy1_zy1.sql
对一个数据库或多个数据库的所有表备份书写格式:-B 库名 库名
[root@mysql01 ~]# mysqldump -uroot -pJY1987...zy2011 -B mysql > /bakdir1/mysql.sql mysqldump: [Warning] Using a password on the command line interface can be insecure. [root@mysql01 ~]# ls /bakdir1/ jy1_zy1.sql mysql.sql
多个数据库进行备份书写格式:-set @@session.gtid_next='anonymous' 库名1 库名2 ……
对一台服务器上的所有数据书写格式:-A 或 --all-databases
[root@mysql01 ~]# mysqldump -uroot -pJY1987...zy2011 -A > /bakdir1/mysql01.sql mysqldump: [Warning] Using a password on the command line interface can be insecure. [root@mysql01 ~]# ls /bakdir1/ jy1_zy1.sql mysql01.sql mysql.sql
4.3、恢复数据
mysql> delete from jy1.zy1; Query OK, 20 rows affected (0.00 sec) mysql> drop table jy1.zy1; Query OK, 0 rows affected (0.01 sec) mysql> show tables; Empty set (0.00 sec) mysql> exit Bye [root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 jy1 < /bakdir1/jy1_zy1.sql mysql: [Warning] Using a password on the command line interface can be insecure. mysql> use jy1; Database changed mysql> show tables; +---------------+ | Tables_in_jy1 | +---------------+ | zy1 | +---------------+ 1 row in set (0.00 sec)
注意:
- 使用表的备份文件恢复表的数据,要在恢复的时候指定恢复的数据库;
- 使用库的备份文件恢复数据,不需要写库名,只能恢复备份之前的数据,之后新添加数据无法恢复。
4.4、编写计划任务备份数据
计划任务:每周周一晚上23点备份服务的所有数据,用系统日期做备份文件命令
[root@mysql01 ~]# crontab -e [root@mysql01 ~]# crontab -l 00 23 * * 1 mysqldump -uroot -pJY1987...zy2011 -A > /bakdir1/`date +%F`_allbak.sql
4.5、mysqlump服务
- 数据库中提供的mysqldump服务需要登陆到数据库中,如果数据库的启动文件或者其他配置文件出现错误,此方法将无法进行正常启动。
- mysqldump备份和恢复时会锁表,锁表就是给表加锁,加锁之后无论是对表做任何命令都不允许,备份或恢复数据操作完成后会自动释放锁,才可以对表作查询或者存储。mysqldump备份命令生成备份文件恢复数据,只能把数据恢复备份时刻的数据。
5、binlog日志文件使用
- mysql服务日志文件的一种:binlog日志启用后,可以实时记录在数据库服务器上执行的除查询之外的所有sql命令,实现对数据的时时备份;
- mysql的四种日志文件:错误日志、查询日志、慢查询日志、binlog日志
- log-error=/var/log/mysqld.log #SET @@SESSION.GTID_NEXT= 'ANONYMOUS' 错误日志的位置
5.1、开启日志 :制定的存放路径需要将文件的属主和属组为mysql,否则会无法重启成功。手动创建日志文件(默认日志文件大于1G时才会自动创建新的日志文件),关闭selinux
[root@mysql01 ~]# vim /etc/my.cnf [mysqld] server_id=10 log_bin [root@mysql01 ~]# systemctl restart mysqld [root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 mysql> show master status; #查看binlog日志信息 +--------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +--------------------+----------+--------------+------------------+-------------------+ | mysql01-bin.000001 | 154 | | | | +--------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> system ls /var/lib/mysql/mysql01* #binlog日志默认存储在数据库目录下 /var/lib/mysql/mysql01-bin.000001 /var/lib/mysql/mysql01-bin.index
5.2、自定义binlog日志信息:主机启用binlog日志时,指定日志文件存放的目录和日志文件命令
[root@mysql01 ~]# vim /etc/my.cnf [mysqld] server_id=10 log_bin=/mylog/jy10 [root@mysql01 ~]# mkdir /mylog [root@mysql01 ~]# chown mysql /mylog [root@mysql01 ~]# setenforce 0 [root@mysql01 ~]# systemctl restart mysqld [root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 -e 'show master status' mysql: [Warning] Using a password on the command line interface can be insecure. +-------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +-------------+----------+--------------+------------------+-------------------+ | jy10.000001 | 154 | | | | +-------------+----------+--------------+------------------+-------------------+ [root@mysql01 ~]# ls /mylog/ jy10.000001 jy10.index [root@mysql01 ~]# cat /mylog/jy10.index /mylog/jy10.000001
5.3、创建新的binlog日志文件:默认情况下日志文件记录的sql命令文件容量大于 1G 的时候,数据服务会自动创建新的日志文件 文件编号顺延。
也可以手动创建新的binlog日志文件记录sql命令如下:
方法一:重启服务 mysql> system systemctl restart mysqld 方法二:创建新日志文件的个数和完全备份数据库的个数相同 [root@mysql01 ~]# mysqldump -uroot -pJY1987...zy2011 --flush-logs -B jy1 > /bakdir1/jy1.sql mysqldump: [Warning] Using a password on the command line interface can be insecure. 方法三:数据库管理员root 执行创建新日志文件的命令 mysql> flush logs; Query OK, 0 rows affected (0.01 sec)
5.4、binlog日志相关管理命令
1、查看正在使用binlog日志名和偏移量(记录sql命令的编号) mysql> show master status; +-------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +-------------+----------+--------------+------------------+-------------------+ | jy10.000006 | 154 | | | | +-------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) 2、查看数据库服务器当前已有全部 binlog日志文件 mysql> show binary logs; +-------------+-----------+ | Log_name | File_size | +-------------+-----------+ | jy10.000001 | 196 | | jy10.000002 | 196 | | jy10.000003 | 177 | | jy10.000004 | 196 | | jy10.000005 | 196 | | jy10.000006 | 154 | +-------------+-----------+ 6 rows in set (0.00 sec) 3、删除编号之前的所有日志文件 mysql> purge master logs to "jy10.000004"; Query OK, 0 rows affected (0.00 sec) 4、删除当前所有的日志文件重新创建新日志文件和索引文件 mysql> reset master; Query OK, 0 rows affected (0.01 sec) 5、查看日志文件内容 2 种方法 mysql> show binlog events in "jy10.000001"; #使用sql命令查看 +-------------+-----+----------------+-----------+-------------+---------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +-------------+-----+----------------+-----------+-------------+---------------------------------------+ | jy10.000001 | 4 | Format_desc | 10 | 123 | Server ver: 5.7.17-log, Binlog ver: 4 | | jy10.000001 | 123 | Previous_gtids | 10 | 154 | | +-------------+-----+----------------+-----------+-------------+---------------------------------------+ 2 rows in set (0.00 sec) [root@mysql01 ~]# mysqlbinlog /mylog/jy10.000001 #使用系统命令 mysqlbinlog 查看
5.5、binlog日志恢复数据文件:读取日志文件的所有内容恢复数据,适用于日志里没有记录delete from的命令;恢复指定的数据,适用于日志文件交替出现insert update delete的命令;
格式一:mysqlbinlog /目录名/日志文件名 | mysql -uroot -p密码
完全备份 tarena 库,并在完成备份后创建新的日志文件
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | jy1 | | mysql | | performance_schema | | sys | | tarena | +--------------------+ 6 rows in set (0.00 sec) mysql> exit Bye [root@mysql01 ~]# mysqldump -uroot -pJY1987...zy2011 --flush-logs -B tarena > /bakdir/`date +%F`_tarena.sql mysqldump: [Warning] Using a password on the command line interface can be insecure. [root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 -e "show master status" mysql: [Warning] Using a password on the command line interface can be insecure. +-------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +-------------+----------+--------------+------------------+-------------------+ | jy10.000002 | 154 | | | | +-------------+----------+--------------+------------------+-------------------+
完全备份后管理员root登陆继续插入新的记录
[root@mysql01 ~]# mysql -uroot -pJY1987...zy2011
mysql> insert into tarena.user(name,uid) values("jy",1987);
mysql> insert into tarena.user(name,uid) values("xb",1987);
mysql> insert into tarena.user(name,uid) values("zy",2011);
mysql> show master status;
+-------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------+----------+--------------+------------------+-------------------+
| jy10.000002 | 985 | | | |
+-------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
把binlog日志和备份文件拷贝给02
[root@mysql01 ~]# scp /mylog/jy10.000002 192.168.4.20:/root/ #将日志拷贝给02 [root@mysql01 ~]# scp /bakdir/2022-05-15_tarena.sql 192.168.4.20:/root/ #将备份拷贝给02
02使用01的备份文件恢复
[root@mysql02 ~]# mysql -uroot -p123qqq...A -e 'show databases' mysql: [Warning] Using a password on the command line interface can be insecure. +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ [root@mysql02 ~]# ls 2022-05-15_tarena.sql anaconda-ks.cfg jy10.000002 [root@mysql02 ~]# mysql -uroot -p123qqq...A < /root/2022-05-15_tarena.sql mysql: [Warning] Using a password on the command line interface can be insecure. [root@mysql02 ~]# mysqlbinlog /root/jy10.000002 | mysql -uroot -p123qqq...A [root@mysql02 ~]# mysql -uroot -p123qqq...A #登录数据库,管理员检查
格式二:mysqlbinlog 选项 /目录名/日志文件名 | mysql -uroot -p密码
查看日志的部分内容恢复数据(恢复部分数据) 适用于 既有insert 又有delete的情况
根据选项指定的范围查看记录的sql命令,选项包括:
查看指定偏移量范围内记录的sql命令
--start-position=开始偏移量 --stop-position=结束偏移量
查看指定时间范围内记录的sql命令
--start-datetime="yyyy/mm/dd hh:mm:ss" --stop-datetime="yyyy/mm/dd hh:mm:ss"
修改binlog日志文件的格式(格式就是日志文件记录sql命令的方式)
mysql> show variables like "binlog_format"; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | binlog_format | ROW | #行格式看不到具体的sql命令,想看到具体的sql命令要修改日志格式。 +---------------+-------+ 1 row in set (0.01 sec) mysql> exit Bye [root@mysql01 ~]# vim /etc/my.cnf [mysqld] server_id=10 log_bin=/mylog/jy10 binlog_format="mixed" #添加 [root@mysql01 ~]# systemctl restart mysqld mysql> show variables like "binlog_format"; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | binlog_format | MIXED | +---------------+-------+ 1 row in set (0.00 sec) mysql> show master status; +-------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +-------------+----------+--------------+------------------+-------------------+ | jy10.000003 | 154 | | | | +-------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)
对数据库执行 select insert update delete 命令
mysql> select count(*) from tarena.user;
+----------+
| count(*) |
+----------+
| 26 |
+----------+
1 row in set (0.01 sec)
mysql> insert into tarena.user(name,uid) values("jy",777);
mysql> insert into tarena.user(name,uid) values("zy",999);
mysql> insert into tarena.user(name,uid) values("xb",222);
mysql> select count(*) from tarena.user;
+----------+
| count(*) |
+----------+
| 29 |
+----------+
1 row in set (0.00 sec)
mysql> show master status;
+-------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------+----------+--------------+------------------+-------------------+
| jy10.000003 | 1135 | | | |
+-------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql> delete from tarena.user where uid=222;
Query OK, 1 row affected (0.01 sec)
mysql> show master status;
+-------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------+----------+--------------+------------------+-------------------+
| jy10.000003 | 1417 | | | |
+-------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql> insert into tarena.user(name,uid) values("xb",888);
Query OK, 1 row affected (0.00 sec)
mysql> insert into tarena.user(name,uid) values("xb",222);
Query OK, 1 row affected (0.00 sec)
mysql> show master status;
+-------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------+----------+--------------+------------------+-------------------+
| jy10.000003 | 2071 | | | |
+-------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
通过指定偏移量范围恢复数据:--start-position=偏移量 --stop-position=偏移量
只读取范围内的命令管道给连接数据库服务命令执行
mysql> show binlog events in "jy10.000003"; [root@mysql01 ~]# mysqlbinlog --start-position=1886 --stop-position=2040 /mylog/jy10.000003 | mysql -uroot -pJY1987...zy2011 mysql: [Warning] Using a password on the command line interface can be insecure. [root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 -e 'select * from tarena.user'
通过指定时间范围恢复数据:
--start-datetime="yyyy/mm/dd hh:mm:ss" --stop-datetime="yyyy/mm/dd hh:mm:ss"
[root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 -e 'select * from tarena.user where name="xb"' mysql: [Warning] Using a password on the command line interface can be insecure. +----+------+----------+------+------+---------+---------+-------+ | id | name | password | uid | gid | comment | homedir | shell | +----+------+----------+------+------+---------+---------+-------+ | 29 | xb | NULL | 1987 | NULL | NULL | NULL | NULL | | 34 | xb | NULL | 888 | NULL | NULL | NULL | NULL | | 35 | xb | NULL | 222 | NULL | NULL | NULL | NULL | +----+------+----------+------+------+---------+---------+-------+ [root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 -e 'delete from tarena.user where name="xb"' mysql: [Warning] Using a password on the command line interface can be insecure. [root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 -e 'select * from tarena.user where name="xb"' mysql: [Warning] Using a password on the command line interface can be insecure. [root@mysql01 ~]# mysqlbinlog /mylog/jy10.000003 #可以看到命令执行时间和命令执行的偏移量 [root@mysql01 ~]# mysqlbinlog --start-datetime="2022/05/15 18:48:05" --stop-datetime="2022/05/15 18:48:05" /mylog/jy10.000003 | mysql -uroot -pJY1987...zy2011 mysql: [Warning] Using a password on the command line interface can be insecure. [root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 -e 'select * from tarena.user where name="xb"' mysql: [Warning] Using a password on the command line interface can be insecure. +----+------+----------+------+------+---------+---------+-------+ | id | name | password | uid | gid | comment | homedir | shell | +----+------+----------+------+------+---------+---------+-------+ | 35 | xb | NULL | 222 | NULL | NULL | NULL | NULL | +----+------+----------+------+------+---------+---------+-------+
6、percona提供的备份命令innobackupex
使用第三方软件percona提供的备份命令innobackupex对数据做备份和恢复,特点:在线热备不锁表 适合生产环境下备份业务。
6.1、安装软件提供命令
[root@mysql01 ~]# yum -y install libev-4.15-1.el6.rf.x86_64.rpm percona-xtrabackup-24-2.4.7-1.el7.x86_64.rpm
6.2、数据完全备份与恢复,对数据做完全备份也不锁表
格式:innobackupex -uroot -p密码 /备份目录名 --no-timestamp
--no-timestamp可选项,不用系统的日期做存放备份文件的目录名
对数据完全备份
[root@mysql01 ~]# innobackupex -uroot -pJY1987...zy2011 /jy --no-timestamp [root@mysql01 ~]# ls /jy/ backup-my.cnf ib_buffer_pool ibdata1 jy1 mysql performance_schema sys tarena xtrabackup_binlog_info xtrabackup_checkpoints xtrabackup_info xtrabackup_logfile
删除数据
mysql> drop database tarena ;drop database mysql; Query OK, 4 rows affected (0.11 sec) Query OK, 31 rows affected, 2 warnings (0.15 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | jy1 | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec)
恢复数据
[root@mysql01 ~]# systemctl stop mysqld [root@mysql01 ~]# rm -rf /var/lib/mysql/* [root@mysql01 ~]# innobackupex --apply-log /jy/ #准备恢复数据 [root@mysql01 ~]# innobackupex --copy-back /jy/ #准备拷贝数据 [root@mysql01 ~]# chown -R mysql:mysql /var/lib/mysql [root@mysql01 ~]# systemctl start mysqld [root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 -e "show databases" mysql: [Warning] Using a password on the command line interface can be insecure. +--------------------+ | Database | +--------------------+ | information_schema | | jy1 | | mysql | | performance_schema | | sys | | tarena | +--------------------+
6.3、使用完全备份文件恢复1张的数据
[root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 -e 'delete from tarena.user'
mysql> select * from tarena.user;
Empty set (0.00 sec)
恢复表记录,删除表空间 (表名.ibd) 用来存储表记录的文件 select * from 表;删除表空间就是把数据库目录下没有记录的表名.idb文件删除
格式:alter table 库名.表名 discard tablespace;
mysql> alter table tarena.user discard tablespace; Query OK, 0 rows affected (0.00 sec)
导出表信息,生成备份目录下备份数据的信息文件
[root@mysql01 ~]# innobackupex --apply-log --export /jy
[root@mysql01 ~]# cp /jy/tarena/user.{ibd,cfg,exp} /var/lib/mysql/tarena/
[root@mysql01 ~]# chown mysql:mysql /var/lib/mysql/tarena/user.*
导入表空间
mysql> alter table tarena.user import tablespace; Query OK, 0 rows affected, 1 warning (0.11 sec)
删除数据库目录下的表信息文件,查看表记录
[root@mysql01 ~]# rm -rf /var/lib/mysql/tarena/user.{cfg,exp}
[root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 -e "select * from tarena.user"
6.4、数据增量备份与恢复
增量备份是备份上次备份后新产生的数据,所以在执行增量备份之前必须得先有一次备份,否则无法得知那些数据是新数据,通常增量备份之前的备份就应该是完全备份。
完全备份
[root@mysql01 ~]# innobackupex -uroot -pJY1987...zy2011 /zy --no-timestamp
[root@mysql01 ~]# ls /zy/
backup-my.cnf ib_buffer_pool ibdata1 jy1 mysql performance_schema sys tarena xtrabackup_binlog_info xtrabackup_checkpoints xtrabackup_info xtrabackup_logfile
mysql> insert into tarena.user(name,shell) values("xbt","bbb"); #多执行几次
增量备份 :增量备份是备份上次备份后新产生的数据
增量备份数据格式:
innobackupex -uroot -p密码 --incremental /目录名 --incremental-basedir=/目录名 --no-timestamp
备注:
--incremental 备份新数据并定义新数据存放的目录名
--incremental-basedir 备份新数据参考的备份目录名
[root@mysql01 ~]# innobackupex -uroot -pJY1987...zy2011 --incremental /zlzy --incremental-basedir=/zy --no-timestamp #周二执行 [root@mysql01 ~]# ls /zlzy/ [root@mysql01 ~]# innobackupex -uroot -pJY1987...zy2011 --incremental /zl2zy --incremental-basedir=/zlzy --no-timestamp #周三执行
差异备份:差异备备就是完全备份后新产生的数据
[root@mysql01 ~]# innobackupex -uroot -pJY1987...zy2011 --incremental /cyzy --incremental-basedir=/zy --no-timestamp #周二执行 [root@mysql01 ~]# innobackupex -uroot -pJY1987...zy2011 --incremental /cy2zy --incremental-basedir=/zy --no-timestamp #周三执行
增量恢复数据
格式:
准备恢复数据
innobackupex --apply-log --redo-only /首次备份目录名
合并数据 合并的次数与增量备份的顺序要一致
innobackupex --apply-log --redo-only /首次备份目录名 --incremental-dir=/
备注:
--incremental-dir 增量备份数据存放的目录名
删除数据
[root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 -e 'drop database tarena' [root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 -e 'drop database mysql' [root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 -e 'show databases' mysql: [Warning] Using a password on the command line interface can be insecure. +--------------------+ | Database | +--------------------+ | information_schema | | jy1 | | performance_schema | | sys | +--------------------+
增量备份文件恢复数据
注意:合并数据,合并的次数要增量备份的次数一样 并且合并的顺序也有与增量备份的顺序一致
[root@mysql01 ~]# systemctl stop mysqld [root@mysql01 ~]# rm -rf /var/lib/mysql/* [root@mysql01 ~]# innobackupex --apply-log --redo-only /zy/ #指定合并数据的位置 [root@mysql01 ~]# innobackupex --apply-log --redo-only /zy/ --incremental-dir=/zlzy/ [root@mysql01 ~]# innobackupex --apply-log --redo-only /zy/ --incremental-dir=/zl2zy/ [root@mysql01 ~]# innobackupex --copy-back /zy [root@mysql01 ~]# chown -R mysql:mysql /var/lib/mysql [root@mysql01 ~]# systemctl start mysqld [root@mysql01 ~]# mysql -uroot -pJY1987...zy2011 -e 'show databases'



