这是一个与我在stackoverflow上看到的相关InnoDB修复问题略有不同的问题。
假设我已经使用innodb_file_per_table=1在我的MySQL 5.1数据库中恢复了以下内容:
db/tablename.ibd
innodb/ibdata1
innodb/ib_logfile0
innodb/ib_logfile1我弄丢了db/tablename.frm文件。我可以启动数据库服务器,但InnoDB抱怨:
110723 13:26:33 InnoDB: Error: table 'db/tablename'
InnoDB: in InnoDB data dictionary has tablespace id 5943,
InnoDB: but tablespace with that id or name does not exist. Have
InnoDB: you deleted or moved .ibd files?如何重建FRM文件?
发布于 2017-01-31 22:41:29
编辑:我创建了一个简单的脚本,可以完成下面描述的所有步骤:https://ourstickys.com/recover.sh
这是一个老问题,但我找到了更简单的方法:https://dba.stackexchange.com/questions/16875/restore-table-from-frm-and-ibd-file
I have recovered my MySQL 5.5 *.ibd and *.frm files with using MySQL Utilites and MariaDB 10.
1) Generating Create SQLs.
You can get your create sql's from frm file. You must use : https://dev.mysql.com/doc/mysql-utilities/1.5/en/mysqlfrm.html
shell> mysqlfrm --server=root:pass@localhost:3306 c:\MY\t1.frm --port=3310
Other way you may have your create sql's.
2) Create Your Tables
Create your tables on the database.
3) alter table xxx discard tablespace
Discard your tables which do you want to replace your *.ibd files.
4) Copy your *.ibd files (MySQL Or MariaDB) to MariaDB's data path
First i try to use MySQL 5.5 and 5.6 to restrore, but database crashes and immediately stops about tablespace id broken error. (ERROR 1030 (HY000): Got error -1 from storage engine)
After i have used MariaDB 10.1.8, and i have succesfully recovered my data.
5) alter table xxx import tablespace
When you run this statement, MariaDB warns about file but its not important than to recover your data :) Database still continues and you can see your data.
I hope this information will helpful for you.让我补充一下,您可以在这里下载mysqlfrm:https://dev.mysql.com/downloads/utilities/
我还发现了一种使用dbsake获取CREATE TABLE的更快的方法
curl -s http://get.dbsake.net > dbsake
chmod u+x dbsake然后:
#only one table
./dbsake frmdump /path/to/table.frm > recover.sql
#multiple tables
./dbsake frmdump /path/to/*.frm > recover.sql然后是:
mysql -uUSER -p recover_db < recover.sql如果需要,您还可以在one行中执行它:
./dbsake frmdump /path/to/*.frm | mysql -uUSER -p recover_db此时,您可以从第3点开始按照上面的说明进行操作。
发布于 2011-07-24 22:31:27
我自己想出了一个解决方案。
简单的解决方案是找到保存的FRM副本,在开发实例上运行它,然后将生成的CREATE TABLE文件复制到恢复的实例。
然而,在我的例子中,我没有可用的CREATE TABLE命令的副本。
您可以使用ibdata、ib_logfiles和*.ibd文件运行MySQL服务器。但是,如果没有FRM,数据库中将看起来没有表。
在恢复的数据库中,运行create table innodb_table_monitor (a int) ENGINE=InnoDB
create table innodb_table_monitor (a int) ENGINE=InnoDB
drop table innodb_table_monitor
表:名称db/mylosttable,id 0 7872,标志1,列5,索引1,appr.rows 1828列: id: DATA_MYSQL DATA_NOT_NULL len 12;名称: type 12 DATA_NOT_NULL len 45;DB_ROW_ID: DATA_SYS prtype 256 len 6;DB_TRX_ID: DATA_SYS prtype 257 len 6;DB_ROLL_PTR: DATA_SYS prtype 258 len 7;索引:名称GEN_CLUST_INDEX,id 0 17508,字段0/5,uniq 1,类型1根页面3,appr.key值1828,叶页面9,大小页面10字段: DB_ROW_ID DB_TRX_ID DB_ROLL_PTR id name
可以表示为:
如果存在mylosttable,则删除table;创建table mylosttable( id char(12) NOT NULL,name varchar(45) NOT NULL );
如果您对表监视器输出感到困惑,请查看具有已知方案的表的输出。
注意:您可以将FRM文件复制到实时数据库实例中。上面停止服务器的原因是,如果在创建innodb_table_monitor表之后使数据库崩溃,将使ibdata文件处于不一致的状态,您将不得不从备份重新开始。
select *语句测试表是否正常工作。如果你错了,你会看到:错误2013 (HY000):在query期间丢失与MySQL服务器的连接
这意味着数据库已经崩溃了。
如果发生这种情况,请在开发实例上执行create table innodb_table_monitor...,并将输出与恢复的实例的原始输出进行比较。你很可能会发现你遗漏了一个非空值或类似的小东西。
https://stackoverflow.com/questions/6804397
复制相似问题