环境:
OS:Centos 7
1.先安装好mysql5.6
安装步骤情参考
http://blog.chinaunix.net/uid-77311-id-5756583.html
2.从阿里云rds下载备份集
我这里下载的备份集如下:
hins12503237_data_20200425055654_qp.xb
3.安装xtrabackup
[root@izwz9gxsbwybwg9n5xdi47z opt]# tar -zxvf percona-xtrabackup-2.4.7-Linux-x86_64.tar.gz
[root@izwz9gxsbwybwg9n5xdi47z opt]# mv percona-xtrabackup-2.4.7-Linux-x86_64 /opt/xtrabackup247
4.停止mysql,备份data目录
./mysqladmin -h localhost -S /opt/mysql5640/data/mysql.sock -uroot shutdown
备份data目录
[root@localhost mysql5640]# mv data bakdata
创建空的data目录
[root@localhost mysql5640]# mkdir data
5.安装好 XtraBackup 之后,使用 xbstream 命令将备份文件解包到目标目录。
[root@localhost bin]# /opt/xtrabackup247/bin/xbstream -x -v -C /opt/mysql5640/data</soft/rds/hins12503237_data_20200425055654_qp.xb ##说明/opt/mysql5640/data是数据还原的目录
执行后的问题是这样的,文件都是以qp后缀命名的
[root@localhost bin]# ls -al /opt/mysql5640/data
total 3284
drwxr-xr-x 6 root root 4096 Apr 26 10:33 .
drwxr-xr-x 17 mysql mysql 4096 Apr 26 09:54 ..
-rw-r----- 1 root root 407 Apr 26 10:33 backup-my.cnf.qp
drwxr-x--- 2 root root 4096 Apr 26 10:33 db_queueflow
-rw-r----- 1 root root 3017576 Apr 26 10:33 ibdata1.qp
-rw-r----- 1 root root 229601 Apr 26 10:33 log000000000002.tokulog29.qp
drwxr-x--- 2 root root 4096 Apr 26 10:33 mysql
drwxr-x--- 2 root root 4096 Apr 26 10:33 performance_schema
-rw-r----- 1 root root 44921 Apr 26 10:33 rds_table_info_json_51822.log
drwxr-x--- 2 root root 4096 Apr 26 10:33 test
-rw-r----- 1 root root 528 Apr 26 10:33 tokudb.directory.qp
-rw-r----- 1 root root 642 Apr 26 10:33 tokudb.environment.qp
-rw-r----- 1 root root 527 Apr 26 10:33 tokudb.rollback.qp
-rw-r----- 1 root root 164 Apr 26 10:33 xtrabackup_binlog_info.qp
-rw-r----- 1 root root 115 Apr 26 10:33 xtrabackup_checkpoints
-rw-r----- 1 root root 773 Apr 26 10:33 xtrabackup_info.qp
-rw-r----- 1 root root 425 Apr 26 10:33 xtrabackup_logfile.qp
-rw-r----- 1 root root 162 Apr 26 10:33 xtrabackup_slave_filename_info.qp
-rw-r----- 1 root root 194 Apr 26 10:33 xtrabackup_slave_info.qp
使用 qpress 命令将目标目录下所有以.qp结尾的文件都解压出来.
[root@localhost bin]# /opt/xtrabackup247/bin/xtrabackup --decompress --remove-original --target-dir=/opt/mysql5640/data ##--remove-original的意思是删除解压后原来的压缩文件
./xtrabackup version 2.4.7 based on MySQL server 5.7.13 Linux (x86_64) (revision id: 05f1fcf)
200426 10:35:24 [01] decompressing ./xtrabackup_slave_filename_info.qp
sh: qpress: command not found
cat: write error: Broken pipe
Error: thread 0 failed.
解决办法:
# wget http://www.quicklz.com/qpress-11-linux-x64.tar 或是直接登陆网站进行下载
# tar xvf qpress-11-linux-x64.tar
# cp qpress /usr/bin
Prepare 备份文件
备份解压出来之后,需要执行以下命令进行 apply log 操作。
/opt/xtrabackup247/bin/innobackupex --defaults-file=/opt/mysql5640/conf/my.cnf --apply-log /opt/mysql5640/data
6.重新修改mysql目录权限
[root@localhost mysql5640]# cd /opt/mysql5640
[root@localhost mysql5640]# chown -R mysql:mysql ./data
7.启动数据库
./mysqld_safe --defaults-file=/opt/mysql5640/conf/my.cnf --user=mysql &
[root@localhost bin]# ./mysql -h localhost -uroot -S /opt/mysql5640/data/mysql.sock
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
这里是无法登录数据库的,我们可以尝试跳过密码启动数据库
在启动配置项里添加如下项目,然后进程重新启动
skip-grant-tables=1
--The End --