我以前保存了/ var / lib / mysql / ddms目录的副本(“ ddms”是架构名称)。现在,我通过运行apt-get install mysql-server在新安装的Ubuntu 10.04.3 LTS上安装了新的MySQL,我相信已经安装了5.1版。复制完/ var / lib / mysql下的ddms目录后,它的某些表可以正常工作,这些表具有三个文件的关联集:.frm文件,.MYD文件和.MYI文件。 />
但是,有两个表具有一组不同的文件:.frm文件和.ibd文件。这两个表未显示在phpMyAdmin的表列表中。当我查看错误日志时,它显示:

[ERROR] Cannot find or open table ddms/dictionary_item 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.


请帮助还原这两个表。谢谢。

评论

Rolando在12月4月23日的报价今天仍然有效。 “只是将.frm和.ibd文件从一个位置复制到另一个位置就麻烦了。”使用mysqldump这样的替代方法,可以将旧数据转换成可以按计划在几年前加载的表单。也称为备份。

#1 楼

InnoDB表不能像MyISAM表一样复制。

将.frm和.ibd文件从一个位置复制到另一个位置会带来麻烦。仅当且仅当您可以确保.ibd文件的表空间ID与ibdata1文件的metdata中的表空间ID项完全匹配时,才可以复制InnoDB表的.frm和.ibd文件。

我在DBA StackExchange中写了两篇有关此表空间ID概念的文章



InnoDB中的表压缩? (在“还原数据库”标题下)
如何恢复文件已移动的InnoDB表

这里是有关如何在发生以下情况时将任何.ibd文件重新附加到ibdata1的绝佳链接。表空间ID不匹配:http://www.chriscalender.com/?tag=innodb-error-tablespace-id-in-file。读完这篇文章后,您应该立即意识到复制.ibd文件简直是疯了。

您可以应用Chris Calendar链接中的建议,或者可以回到以前的安装mysql,启动mysql,然后mysqldump ddms数据库。然后,将该mysqldump导入新的mysql实例。相信我,这会容易得多。

评论


因此,单个表可能不是一个好主意,但是那时整个数据库又如何呢?我的用户表崩溃严重,我必须在mysqld上执行--initialize。我可以从data_backup文件夹复制整个InoDB数据库文件夹吗?

–FMaz008
17年7月7日在6:37

罗兰多,以防万一您可以帮助我:serverfault.com/q/908988/224334

–IonicăBizău
18年4月23日在12:28

您有关如何恢复文件移动的InnoDB表的帖子从字面上挽救了我的生命。非常感谢你。

– Paulo Griiettner
19年3月13日在3:17

#2 楼

我最近遇到了同样的问题。这是我用来解决此问题的步骤,而不必弄乱RolandoMySQLDBA上面提到的表空间ID。我在Mac上,因此我使用MAMP来将数据库还原到可以在MySQL转储中导出的位置。

您可以在此处阅读有关它的完整博客文章:http ://www.quora.com/Jordan-Ryan/Web-Dev/How-to-Recover-innoDB-MySQL-files-using-MAMP-on-a-Mac

您必须具有:

-ibdata1

-ib_logfile0

-ib_logfile1

-.FRM文件来自mysql_database文件夹

-您愿意销毁的MAMP / MAMP Pro的最新安装(如果需要)


SSH进入Web服务器(开发,生产,没有区别)并浏览到您的mysql文件夹(我的Linux上是在/ var / lib / mysql上进行的Plesk安装)
压缩mysql文件夹
下载mysql文件夹的归档文件,其中应包含所有mySQL数据库,无论是MyISAM还是innoDB (您可以将这个文件压缩,或将它移动到可下载的目录中,如果需要的话)
安装MAMP(Mac,Apache,MySQL,PHP)
浏览到/ Applications / MAMP / db / mysql /
Ba ckup / Applications / MAMP / db / mysql到zip存档(以防万一)

从生产服务器(在我的mt Plesk环境中)复制mysql文件夹的存档中包含的所有文件夹和文件情况)请勿覆盖:

-/ Applications / MAMP / db / mysql / mysql /

-/ Applications / MAMP / db / mysql / mysql_upgrade_info

-// Applications / MAMP / db / mysql / performance_schema

瞧,您现在应该可以从phpMyAdmin访问数据库了,真是放心!

但是我们还没有完成,现在您需要执行mysqldump才能将这些文件还原到生产环境中,并且大型数据库的phpmyadmin接口超时。
请按照以下步骤操作:

http://nickhardeman.com/308/export-import-large-database-using-mamp-with-terminal//

复制以下以供参考。请注意,在默认的MAMP安装中,密码为“ root”。

如何使用Terminal

从MAMP [1]导出数据库来为MAMP运行mysqldump。
第一步:
打开一个新的终端窗口

第二步:
通过在终端中输入以下行来导航到MAMP安装:cd / applications / MAMP / library / bin
按回车键

第三步:
编写转储命令
。/mysqldump-u [USERNAME] -p [DATA_BASENAME] > [PATH_TO_FILE]
按Enter键

示例:

./mysqldump -u root -p wp_database > /Applications/MAMP/htdocs/symposium10_wp/wp_db_onezero.sql


快速提示:可以快速导航到文件夹将文件夹拖到终端窗口中,它将写入文件夹的位置。这是美好的一天,有人向我展示了此内容。

第四步:
按回车键后应显示以下文本行
输入密码:
所以你猜怎么着,输入密码,请记住不会出现字母,但它们会出现在这里。
按Enter键

第五步:
检查存储密码的位置文件,如果有的话,成功
现在您可以导入数据库,接下来将概述。

现在您已经导出了mysql数据库,则可以在生产环境中导入它环境。

评论


截至2018年仍在工作。答案是金。对我来说,重要的部分是#7,这些文件是您绝对必须保留的文件(类似解决方案在其他任何地方都没有提到过,感谢@jordan)。

– Bigood
18年5月29日在0:24

@Bigood很高兴它仍在提供帮助!

–乔丹·瑞安(Jordan Ryan)
18年11月26日在8:24

转储时出现错误1146表不存在

–罗伯特·辛克莱尔
19年11月20日在2:24

您也可以使用PHPMyAdmin进行导出(代替Termina的mysqldump)。

– Paul Schreiber
20年5月9日在17:21

#3 楼

我已经使用MySQL Utilites和MariaDB 10恢复了MySQL 5.5 * .ibd和* .frm文件。

1)生成创建SQL。
您可以从frm文件中获取创建sql。您必须使用:https://downloads.mysql.com/archives/utilities/shell> mysqlfrm --server = root:pass @ localhost:3306 c:\ MY \ t1.frm --port = 3310
其他

2)创建表
在数据库上创建表。

3)alter table xxx丢弃表空间
丢弃要替换* .ibd文件的表。

4)将* .ibd文件(MySQL或MariaDB)复制到MariaDB的数据路径
首先我尝试使用MySQL 5.5和5.6进行恢复,但数据库崩溃并立即因表空间ID损坏错误而停止。 (错误1030(HY000):存储引擎出现错误-1)
使用完MariaDB 10.1.8后,我成功恢复了数据。

5)alter table xxx import表空间
运行此语句时,MariaDB警告文件,但它并不重要于恢复数据:)数据库仍在继续,您可以看到您的数据。

我希望这些信息会对您有帮助。

评论


这对我有用。尽管mysqlfrm(尝试使用MySQL 5.6和5.7的1.3.5和1.6.5版本)没有给出正确的CREATE定义,即使使用MySQL 5.7(MySQL 5.7.9中的默认ROW_FORMAT更改)也导致架构不匹配(预期FSP_SPACE_FLAGS =导入表空间时,0x21,.ibd文件包含0x0。)在CREATE语句的末尾手动添加ROW_FORMAT = compact可以解决问题。

–贾尼斯·埃默里斯(JānisElmeris)
17年7月26日在11:30

@JānisElmeris>在CREATE语句末尾手动添加ROW_FORMAT = compact可以解决问题。那也对我有用。谢谢! 👍

– Synetech
19-10-12在14:52

先生,您是救命稻草。出现错误-1可能会导致我丢失大量数据。

– Ben Hillier
20-09-12的16:29

#4 楼

我只有文件作为备份时遇到了完全相同的问题。

我要解决的问题是将数据库文件复制到/ var / lib / mysql / yourdb和放置的ibdata1中在/ var / lib / mysql中。

然后我能够验证我是否可以访问表mysql -u root -p dbname并查询一些先前损坏的表。

之后,我使用mysqldump -u root -p [root_password] [database_name]> dumpfilename.sql对数据库进行了转储。

#5 楼

如果您使用的是MAMP,则在复制完文件后无法启动MySQL,我将innodb_force_recovery = 2放入了my.ini中,然后便能够使mysql启动并导出数据库。

#6 楼

注意:请尝试安装相同版本的MySQL,如果崩溃的MySQL版本是5.6,请安装MySQL 5.6。 (brew install mysql@5.6)。如果以下过程失败,请对MariaDB尝试相同的操作。 (在我的情况下,对于MariaDB,我会取回所有数据库)

进程1


在开始之前,必须停止MySQL或MariaDB。使用此命令(brew services stop mysql),对于MariaDB brew services stop mariadb从备份mysql文件夹复制ibdata1文件,并将其粘贴并替换到新安装的mysql文件夹的ibdata1(usr / local / var / mysql)或mamp / xampp mysql中文件夹位置。
ib_logfile0和ib_logfile1无需先替换。如果上述过程不起作用,请从备份mysql文件夹复制此文件并替换。 (就我而言,我没有替换)
现在从备份mysql文件夹中复制1个数据库进行测试(例如:testdb),并将其粘贴到新安装的mysql文件夹中。在testdb中必须具有.frm和.ibd文件。
重新启动mysql / mariadb(通过服务启动mysql)或(通过服务启动mariadb)
登录MySQL-> mysql -u root -p
如果一切顺利,则mysql登录成功。
现在检查数据库,显示数据库;
使用testdb;
显示表;
SELECT * FROM testdbtable;
如果没有, t显示任何消息,然后成功恢复。

进程2


如果process1不起作用,则必须安装mysqlfrm(https://downloads.mysql .com / archives / utilities /)
要查找数据库表架构>> mysqlfrm --diagnostic / BACKUP / mysql / testdb> /RESTORE/testdb.sql
在记事本/ sublime中打开testdb.sql,您将请参阅所有数据库表架构,但不能查看数据。
在每个CREATE TABLE .... ENGINE = InnoDB末尾添加ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;,否则可能无法创建表。
创建新的数据库“ newtestdb”并运行命令>> mysqldump -uroot -p --databases newtestdb > testdb.sql

它应该创建所有数据库表,现在,如果在“ newtestdb”中进行检查,则会看到.frm和.ibd文件。
现在再次登录mysql >> mysql -u root -p


SHOW DATABASES;
USE newtestdb;

对于所有表,逐一运行此命令,如果您检查newtestbd .ibd文件将消失,则请执行ALTER TABLE tablename DISCARD TABLESPACE;
现在仅从备份数据库testdb文件夹中复制.ibd文件并将其粘贴到newtestdb中。
现在运行ALTER TABLE tablename IMPORT TABLESPACE;

现在希望您将取回数据。


#7 楼

如果您能够将* .ibd文件恢复到原始MySQL服务器,请不要忘记也恢复文件访问权限。
就我而言(在CentOS7上为MySQL8),我将文件还原到/var/lib/mysql/db/tablename.ibd并运行:

chown mysql tablename.ibd
chgrp mysql tablename.ibd
chmod 0640 tablename.ibd


修复访问权限,访问该表导致错误“ 2006 MySQL服务器已消失”。
修复访问权限后,该表起作用(即使不重新启动mysqld服务)。

#8 楼

我已经收集了来自类似主题的帖子(其答案未在此处发布):

解决方案1:https://dba.stackexchange.com/a/59978


解决方案2:https://dba.stackexchange.com/a/71785(+那里的其他帖子)

解决方案3:表格恢复工具包:https://twindb.com/how-to -recover-innodb-dictionary /

解决方案4:从ibd文件中从没有ibdata1的数据文件夹中恢复MySQL数据库

解决方案5:使用mysqlfrm命令

解决方案6:https://dba.stackexchange.com/a/159001

解决方案7:https://dba.stackexchange.com/a/144573

评论


这看起来可疑地像仅链接的答案。

–必须
17年1月6日在18:28

因为所有链接都来自我们自己的站点,所以它们不太可能消失,所以我对这个@mustaccio表示满意

– jcolebrand♦
17年1月6日在19:05

这似乎并没有增加太多价值,因为其中大多数也出现在“相关”列表的右侧,只有几个像素。

–必须
17年1月6日在19:31

@jcolebrand感谢您的开明。许多人甚至看不到这种“非直接”答案的用处。他们只能检测规则的突破。

–T.Todua
17年1月7日14:07



不,但您必须了解他是对的。您没有添加任何值。我以规则判断作为回应,而不是原谅您的回答。这实际上是一个很糟糕的答案。

– jcolebrand♦
17年1月7日在16:18

#9 楼

我只想为macOS El Capitan用户添加一件事。该版本不支持MySQL实用程序,因此mysqlfrm命令没有帮助。我所做的是使用dbsake恢复表结构,如以下链接所示:https://www.percona.com/blog/2015/12/16/recovering-table-structure-from-frm-files-using-dbsake/

您需要做的就是安装dbsake:

# curl -s http://get.dbsake.net > dbsake
# chmod u+x dbsake


,然后使用frmdump命令并提供.frm文件的路径:

# ./dbsake frmdump /var/lib/mysql/sakila/staff.frm


您将获得create语句。
完成此操作后,我只需遵循@Ecd已经提到的步骤2至5。
希望对别人有帮助。

#10 楼

我非常感谢Ecd。
对我有用的是:

1.-几个月前我对基准进行了备份
,这有助于我在xampp中提升此备份。 Windows 10并创建表以具有结构
(配置:Windows 10,xampp-windows-x64-7.1.30-5-VC14)
mysql my.ini配置文件位于结束

NOTE: Some tables did not have ROW_FORMAT = COMPACT, so I went to operations on each 
    table and changed it manually.
    (If I did not do that, an error appeared and I did not let the import).

NOTE2: I had the backup of months ago but it should also work by first recovering 
    the structure of the .frm files in case of not having a backup at hand.
    (You can try this link:
    https://www.percona.com/blog/2014/01/02/recover-table-structure-frm-files-mysql- 
    utilities/)


2.-建立了旧数据库,我继续对数据库中的每个表执行
alter table xxx丢弃表空间
我想恢复的文件,则删除了C:/ xampp / mysql / data / system中
数据文件夹中的.ibd文件(在这种情况下,
是此路径)

3.--我继续将要恢复的数据库中的.ibd文件复制到旧数据库的
xampp文件夹中。

4.-复制文件后,运行:
alter table xxx import tablespace
对于数据库中的每个表,都会出现一个警告,但是我们将点燃对其进行处理,
数据将被加载到表中,以后可以导出。

5.-将整个数据库导出到sql文件中,然后继续在
中进行构建生产和成功!

# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# You can copy this file to
# C:/xampp/mysql/bin/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is C:/xampp/mysql/data) or
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client] 
# password       = your_password 
port            = 3306 
socket          = "C:/xampp/mysql/mysql.sock"


# Here follows entries for some specific programs 

# The MySQL server
[mysqld]
port= 3306
socket = "C:/xampp/mysql/mysql.sock"
basedir = "C:/xampp/mysql" 
tmpdir = "C:/xampp/tmp" 
datadir = "C:/xampp/mysql/data"
pid_file = "mysql.pid"
# enable-named-pipe
key_buffer = 160M
max_allowed_packet = 300M
sort_buffer_size = 1204K
net_buffer_length = 80K
read_buffer_size = 512K
read_rnd_buffer_size = 1024K
myisam_sort_buffer_size = 8M
log_error = "mysql_error.log"

# Change here for bind listening
# bind-address="127.0.0.1" 
# bind-address = ::1          # for ipv6

# Where do all the plugins live
plugin_dir = "C:/xampp/mysql/lib/plugin/" 

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
# 
# commented in by lampp security
#skip-networking
#skip-federated

# Replication Master Server (default)
# binary logging is required for replication
# log-bin deactivated by default since XAMPP 1.4.11
#log-bin=mysql-bin

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id   = 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =   <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin


# Point the following paths to different dedicated disks
#tmpdir = "C:/xampp/tmp"
#log-update = /path-to-dedicated-directory/hostname

# Uncomment the following if you are using BDB tables
#bdb_cache_size = 40M
#bdb_max_lock = 10000

# Comment the following if you are using InnoDB tables
#skip-innodb
innodb_data_home_dir = "C:/xampp/mysql/data"
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = "C:/xampp/mysql/data"
#innodb_log_arch_dir = "C:/xampp/mysql/data"
## You can set .._buffer_pool_size up to 50 - 80 %
## of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 16M
## Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 50M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 600

## UTF 8 Settings
#init-connect=\'SET NAMES utf8\'
#collation_server=utf8_unicode_ci
#character_set_server=utf8
#skip-character-set-client-handshake
#character_sets-dir="C:/xampp/mysql/share/charsets"
sql_mode=NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION
log_bin_trust_function_creators = 1

[mysqldump]
quick
max_allowed_packet = 160M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout



希望对遇到这种情况的人有所帮助。

Google提供的英语

#11 楼

尝试使用mysql实用程序运行它

mysqlfrm --diagnostic /Users//data/tbl_user.frm 


命令/ shell promt

评论


参考:dev.mysql.com/doc/mysql-utilities/1.5/en/mysqlfrm.html

–夸吉
17年2月16日在9:42