mysql innodb 数据恢复,mysql innodb数据恢复

这几天在从一台已经启动不了的机器上恢复一个web应用。其中数据库使用的是mysql,部分表采用myisam,部分表采用了innodb。但是innodb没有采用一个表一个数据文件的形式,也就是说,所有的数据都在一个ibdata1文件中。

由于那台机器已经无法启动,通过无盘系统进入之后,将mysql的data目录整体复制出来,在另一台服务器上试图恢复数据。

首先,先将数据库文件复制到新机器的mysql data对应的目录中,然后启动mysql,能看见之前的表,但是无法查询出数据。有一下异常日志:

[ERROR] Cannot find or open table process2/process_risk from

the internal data dictionary of InnoDB though the .frm file for the

table exists. Maybe you have deleted and recreated InnoDB data

files but have forgotten to delete the corresponding .frm files

of InnoDB tables, or you have moved .frm files to another database?

or, the table contains indexes that this version of the engine

doesn't support.

具体原因就是之前说过的,这些表都采用了一个数据文件,所有数据都在ibdata1文件中。

然后替换原有的ibdata1文件,启动mysql失败,异常日志为:

InnoDB: Error: auto-extending data file /data/mysqldata1/innodb_ts/ibdata1 is of a different size

InnoDB: 3200 pages (rounded down to MB) than specified in the .cnf file:

InnoDB: initial 131072 pages, max 0 (relevant if non-zero) pages!

InnoDB: Could not open or create data files.

InnoDB: If you tried to add new data files, and it failed here,

InnoDB: you should now edit innodb_data_file_path in my.cnf back

InnoDB: to what it was, and remove the new ibdata files InnoDB created

InnoDB: in this failed attempt. InnoDB only wrote those files full of

InnoDB: zeros, but did not yet use them in any way. But be careful: do not

InnoDB: remove old data files which contain your precious data!

因为没有修改数据文件的配置,这里发现数据文件大小校验失败了。

从这里看见,需要恢复的数据文件有3200页,通过查询mysql文档innodb也结构,可以知道现在mysql innodb每个页的大小是固定的,均为16k,这里的3200页,折算下:3200 * 16 / 1024 = 50M

因此,修改mysql的my.cnf为:

innodb_data_file_path = ibdata1:50M;ibdata2:50M:autoextend

既使用ibdata1文件,标注大小为50M,同时创建ibdata2文件,初始大小为50M,并且自动扩展。

这时候就可以重启mysql,从日志中可以看见,mysql成功加载了ibdata1,并且自动创建了初始大小为50M的ibdata2文件,然后开始恢复数据。数据恢复完成之后,就可以立即使用mysqldump,将对应的整个database导出成sql文件,方面后面恢复到其他mysql中。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值