從阿里云下載hins8247923_data_20191118055735_qp.xb,即*_qp.xb數(shù)據(jù)庫,作如下處理:
一、安裝開源的Percona XtraBackup備份恢復工具:
操作系統(tǒng)中已安裝數(shù)據(jù)恢復工具Percona XtraBackup,可以從Percona XtraBackup官網(wǎng)下載安裝。
MySQL 5.6及之前的版本需要安裝 Percona XtraBackup 2.3,安裝指導請參見https://www.percona.com/doc/percona-xtrabackup/2.3/installation.html?spm=a2c4g.11186623.2.13.3f4d30eb5k7pdZ
MySQL 5.7版本需要安裝 Percona XtraBackup 2.4,安裝指導請參見https://www.percona.com/doc/percona-xtrabackup/2.4/installation.html?spm=a2c4g.11186623.2.14.3f4d30eb5k7pdZ
MySQL 8.0版本需要安裝 Percona XtraBackup 8.0,安裝指導請參見https://www.percona.com/doc/percona-xtrabackup/8.0/installation.html?spm=a2c4g.11186623.2.15.3f4d30eb5k7pdZ
由于我是CentOS7.6的機器,MySQL為5.7的版本,因此:
yum install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
yum list | grep percona
yum install percona-xtrabackup-24
另外,innobackupex解壓命令需要安裝qpress,您可以使用命令yum install qpress -y安裝。
二、解壓文件
對于xbstream 文件包(_qp.xb 后綴),使用命令:
解包
cat <數(shù)據(jù)備份文件名>_qp.xb | xbstream -x -v -C /home/mysql/data
解壓
innobackupex --decompress --remove-original /home/mysql/data
三、物理文件拷貝恢復
1.直接拷貝物理文件至相應的MySQL的Windows機器,沒錯,我這臺是開發(fā)機,因為Web和DB放在同一臺Windows機器上了,生產(chǎn)則是分開的
2.拷貝到相應的位置并更名為需要的數(shù)據(jù)庫名稱,舊的數(shù)據(jù)庫文件夾改其他名稱
3.進mysql查詢相應表格,報錯:
mysql>use xxxbakDB
mysql> select * from UserStudent;
ERROR 1812 (HY000): Tablespace is missing for table saplatformdb.userstudent.
輸入以下命令:
mysql> alter table UserStudent import tablespace;
如果出現(xiàn):
ERROR 1808 (HY000): Schema mismatch (Table has ROW_TYPE_DYNAMIC row format, .ibd
file has ROW_TYPE_COMPACT row format.)
說明表格定義的行格式與表空間不匹配,需要繼續(xù)后續(xù)操作。
4.要先將UserStudent.idb數(shù)據(jù)文件刪除
mysql> alter table Studentfollowlog discard tablespace;
5.顯示查詢建表語句:
mysql> show create table UserStudent;
會出現(xiàn)類似下面一段語句,拷貝它:
CREATE TABLE UserStudent (
Id int(11) NOT NULL AUTO_INCREMENT COMMENT '自增Id',
.......
KEY idx_et (EndDate) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=29172 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='【用戶任務表】' ;
復制以上語句,并將ROW_FORMAT=改成相匹配的ROW_FORMAT=DYNAMIC或ROW_FORMAT=COMPACT。
之間有個小插曲:
一顯示建表語句或做其他查詢,MySQL服務就直接Down掉,不停的關閉,在my.ini中加入以下節(jié):
[mysqld]
innodb_force_recovery = 4
修改完重啟后再查詢show create table UserStudent;
注意:如果后面建表的時候報ERROR 1874 (HY000): InnoDB is in read only mode
記得注釋掉my.ini中的
[mysqld]
#innodb_force_recovery = 4
再重啟MySQL服務
5.然后刪除表后并重建表:
mysql> drop table UserStudent ;
mysql> CREATE TABLE UserStudent (
.....(省略,就是上面那一段)
如果出現(xiàn):ERROR 1808 (HY000): Schema mismatch (Table has ROW_TYPE_DYNAMIC row format, .ibd file has ROW_TYPE_COMPACT row format.)
CREATE TABLE時最后一行要指定:ROW_FORMAT=COMPACT
6.此時看看能不有查詢數(shù)據(jù):
mysql>select from UserStudent limit 0,10 ;
如果出現(xiàn):mysql> select from UserStudent limit 0,10;
ERROR 1812 (HY000): Tablespace is missing for table 'xxxxdb.UserStudent' .
作如下操作:
mysql>alter table UserStudent discard tablespace;
然后將備份文件里面的 UserStudent.ibd 拷貝至現(xiàn)在的數(shù)據(jù)庫位置后,輸入:
mysql> alter table UserStudent import tablespace;
再查詢確認,一般此時表能夠正常查詢了:
mysql>select * from UserStudent limit 0,10