MySQL单表恢复

2019-07-18  本文已影响0人  飞翔的Tallgeese

模拟从坏掉的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表,发现数据已经恢复

上一篇 下一篇

猜你喜欢

热点阅读