美文网首页
MySQL单表恢复

MySQL单表恢复

作者: 飞翔的Tallgeese | 来源:发表于2019-07-18 18:00 被阅读0次

模拟从坏掉的MySQL库中恢复某张表

103库为坏掉的库,需要恢复port表到104库

1.从103库的数据文件中拷贝出port.frm和port.ibd

2.从port.frm中找出建表语句

#安装mysql-utilities

wget https://downloads.mysql.com/archives/get/file/mysql-utilities-1.6.5.tar.gz

tar -xf mysql-utilities-1.6.5.tar.gz

cd mysql-utilities-1.6.5

python setup.py build

python setup.py install

#执行解析语句

mysqlfrm /data/mysql/mysql3306/data/cat/port.frm --port=3306 --user=root --diagnostic

3.发现这个建表语句中包含有外键,删掉建表语句中的外键(一定要确保没有外键)

4.在104库中使用前面解析出的建表语句创建port表

5.让104库中的port表空间脱离

alter table port discard tablespace 

6.复制port.ibd文件到104库data路径下,chown为mysql

7.让104库重新载入port表空间

alter table port import tablespace

8.查询port表,发现数据已经恢复

相关文章

网友评论

      本文标题:MySQL单表恢复

      本文链接:https://www.haomeiwen.com/subject/epkrlctx.html