2020年11月12日星期四

使用您的FRM文件获取Schema,然后导入idb文件。

总的来说,这是一个您永远不必做的主题...为什么?因为您创建的备份是正确的...您已经测试并知道了备份的工作原理,所以您可以仅还原那些备份并获取丢失的架构和相关数据... 

但是,角落办公室中的一个实例..您从来没有进行设置..那不是那么重要...只是崩溃了,现在您认为了您实际上是如何使用它的... 

一切都没有丢失。  

MySQL不久前发布了他们的MySQL实用程序,之后被MySQL Shell所取代。  

mysqlfrm仍然非常方便,但是当需要通过快速简单的命令从FRM文件中提取模式时,这是一个简单的安装。 

mysqlfrm --diagnostic city.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 city.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement:

CREATE TABLE `city` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Name` char(160) DEFAULT NULL,
  `CountryCode` char(12) NOT NULL,
  `District` char(80) NOT NULL,
  `Population` int(11) NOT NULL,
PRIMARY KEY `PRIMARY` (`ID`),
KEY `CountryCode` (`CountryCode`),
KEY `popkey` (`Population`)
) ENGINE=InnoDB;

#...done.


因此,现在您拥有丢失的架构...重建数据库或表。对于这个例子的目的,我会说,我们刚刚从世界DB丢失了城市的数据。 

$ cp  city.ibd  / tmp /  

$ cp city.ibd /tmp/
mysql> LOCK TABLES city WRITE;
mysql> ALTER TABLE city DISCARD TABLESPACE;

cp city.ibd /edb/local/mysql/data/rundeck/
chown tmdba:dba /edb/local/mysql/data/rundeck/city.ibd

mysql> ALTER TABLE city IMPORT TABLESPACE;
mysql> UNLOCK TABLES;
mysql> SELECT COUNT(*) FROM city;