mysql通过frm和ibd恢复Innodb引擎数据

环境说明

操作系统:centos7

mysql版本:5.7.38

innodb:配置了独立表空间

mysql数据文件:xxx.frm 与 xxx.ibd, 其中frm存储的表结构,idb存储的是数据

恢复步骤

1.查看异常的mysql版本,新搭建相同版本的mysql服务

确定版本为5.7.38

[root@VM-32-13-centos ~]# /usr/sbin/mysqld  -version
2023-01-09T01:51:10.026925Z 0 [ERROR] --verbose is for use with --help; did you mean --log-error-verbosity?
2023-01-09T01:51:10.026964Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-01-09T01:51:10.030606Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.38) starting as process 2662467 ...
2023-01-09T01:51:10.043509Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

2023-01-09T01:51:10.043628Z 0 [ERROR] Aborting

2023-01-09T01:51:10.044509Z 0 [Note] Binlog end
2023-01-09T01:51:10.045121Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

2. 通过frm恢复表结构

安装依赖
yum install mysql-utilities
2.1 获取表结构
开始恢复tmp_pv表的表结构
[root@node100]# mysqlfrm --diagnostic tmp_pv.frm
# WARNING: Cannot generate character set or collation names without the --server option.
# CAUTION: The diagnostic mode is a best-effort parse of the .frm file. As such, it may not identify all of the components of the table correctly. This is especially true for damaged files. It will also not read the default values for the columns and the resulting statement may not be syntactically correct.
# Reading .frm file for tmp_pv.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement:

CREATE TABLE `tmp_pv` (
  `md5id` varchar(765) DEFAULT NULL comment '游戏MD5加密', 
  `all_pv` int(11) NOT NULL comment '全部pv' 
) ENGINE=InnoDB;

#...done.
2.2 创建mysql表
mysql执行建表语句
CREATE TABLE `tmp_pv` (
  `md5id` varchar(765) DEFAULT NULL comment '游戏MD5加密', 
  `all_pv` int(11) NOT NULL comment '全部pv' 
) ENGINE=InnoDB;

3 通过ibd恢复表数据

3.1:对刚刚手动创建的tmp_pv表,(表空间卸载同时删除ibd文件)
mysql执行卸载表空间操作,这一步执行完,对应的tmp_pv.ibd也会删除掉
mysql> alter table tmp_pv discard tablespace;

3.2:把原始的tmp_pv.ibd复制过来

3.3:重新装载tmp_pv.ibd
mysql> alter table tmp_pv import tablespace;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

iwester

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值