MySQL 表空间恢复

dbsake是一个MySQL工具集,有解析frm文件的功能

项目地址:https://github.com/abg/dbsake/

1、下载

curl -s get.dbsake.net > dbsake
chmod u+x dbsake

2、解析frm文件,获取表创建SQL语句,比如我们要恢复test表

./dbsake frmdump test.frm

支持通配符

./dbsake frmdump *.frm

相关参数

$ dbsake
Usage: dbsake [options] <command>

Options:
  -d, --debug
  -q, --quiet
  -V, --version  Show the version and exit.
  -?, --help     Show this message and exit.

Commands:
  decode-tablename  Decode a MySQL filename.
  encode-tablename  Encode a MySQL table identifier.
  fincore           Report cached pages for a file.
  frmdump           解析frm文件,获取表创建语句
  help              显示帮助
  sandbox           Create a sandboxed MySQL instance.
  sieve             Filter and transform mysqldump output.
  uncache           Uncache file(s) from the OS page cache.
  upgrade-mycnf     Upgrade a MySQL option file.

3、获得表创建SQL后,到新建的一个数据库里面去执行,创建好表,比如表test

4、然后分离新建表的表空间文件

alter table test discard tablespace;

5、把备份的表空间文件test.ibd文件拷贝到新建数据库目录

6、导入备份的表空间文件

alter table test import tablespace;

7、恢复完成,检查数据

原文地址:https://www.cnblogs.com/lbnnbs/p/14718515.html