MySQL问题 - InnoDB:文件操作中的操作系统错误编号2

7

我在本地开发,使用Mamp Pro。 基本上是MySQL启动时出现问题,以下是错误日志中的错误消息:

您有什么解决方法吗?

2017-03-02 00:39:08 9518 [Note] Plugin 'FEDERATED' is disabled.
2017-03-02 00:39:08 9518 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-03-02 00:39:08 9518 [Note] InnoDB: The InnoDB memory heap is disabled
2017-03-02 00:39:08 9518 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-03-02 00:39:08 9518 [Note] InnoDB: Memory barrier is not used
2017-03-02 00:39:08 9518 [Note] InnoDB: Compressed tables use zlib 1.2.8
2017-03-02 00:39:08 9518 [Note] InnoDB: Using CPU crc32 instructions
2017-03-02 00:39:08 9518 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-03-02 00:39:08 9518 [Note] InnoDB: Completed initialization of buffer pool
2017-03-02 00:39:08 9518 [Note] InnoDB: Highest supported file format is Barracuda.
2017-03-02 00:39:08 9518 [Note] InnoDB: Log scan progressed past the checkpoint lsn 663573438
2017-03-02 00:39:08 9518 [Note] InnoDB: Database was not shutdown normally!
2017-03-02 00:39:08 9518 [Note] InnoDB: Starting crash recovery.
2017-03-02 00:39:08 9518 [Note] InnoDB: Reading tablespace information from the .ibd files...
2017-03-02 00:39:08 9518 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace affiliate_blog_1_old/wpab1_7_woocommerce_order_itemmeta uses space ID: 367 at filepath: ./affiliate_blog_1_old/wpab1_7_woocommerce_order_itemmeta.ibd. Cannot open tablespace freshwp/freshwp_wfblocksadv which uses space ID: 367 at filepath: ./freshwp/freshwp_wfblocksadv.ibd
2017-03-02 00:39:08 7fff7b652000  InnoDB: Operating system error number 2 in a file operation.
InnoDB: The error means the system cannot find the path specified.
InnoDB: If you are installing InnoDB, remember that you must create
InnoDB: directories yourself, InnoDB does not create them.
InnoDB: Error: could not open single-table tablespace file ./freshwp/freshwp_wfblocksadv.ibd
InnoDB: We do not continue the crash recovery, because the table may become
InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it.
InnoDB: To fix the problem and start mysqld:
InnoDB: 1) If there is a permission problem in the file and mysqld cannot
InnoDB: open the file, you should modify the permissions.
InnoDB: 2) If the table is not needed, or you can restore it from a backup,
InnoDB: then you can remove the .ibd file, and InnoDB will do a normal
InnoDB: crash recovery and ignore that table.
InnoDB: 3) If the file system or the disk is broken, and you cannot remove
InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf
InnoDB: and force InnoDB to continue crash recovery here.
170302 00:39:08 mysqld_safe mysqld from pid file /Applications/MAMP/tmp/mysql/mysql.pid ended

根据以上代码,错误似乎是:

2017-03-02 00:39:08 9518 [ERROR] InnoDB: 尝试打开先前打开的表空间。

之前的表空间 affiliate_blog_1_old/wpab1_7_woocommerce_order_itemmeta 使用空间 ID:367,在文件路径中为 ./affiliate_blog_1_old/wpab1_7_woocommerce_order_itemmeta.ibd。

无法打开使用空间 ID:367,在文件路径中为 ./freshwp/freshwp_wfblocksadv.ibd 的表空间 freshwp/freshwp_wfblocksadv。


2
这是一个非常好的错误信息。它不仅告诉你发生了什么和为什么,还提供了3个解决问题的选项。你试过它们吗?(另外:以防万一,先复制你的数据目录)。 - Solarflare
@Solarflare 是的,我尝试了选项3,添加了“innodb_force_recovery> 0”,但没有任何作用。其他解决方案...嗯,我只是不太舒服执行它们/不知道如何执行。 - Treb
@Michael-sqlbot 我正在后台管理页面上为我的WP网站设置并建立网站,一切都很正常,没有什么异常情况。 - Treb
你是怎么添加“innodb_force_recovery> 0”的?这意味着:在[mysqld]下的配置文件中添加例如innodb_force_recovery=1。现在免责声明:在崩溃后(可能是整个系统的崩溃)您的数据库目前已经损坏。任何尝试修复它的操作都可能会使其更加糟糕。强制恢复将在大多数情况下丢失该表中的数据,以及可能还有其他数据,因此您必须从备份中替换它(就像选项2一样)或重新开始。我们无法保证您不会进一步破坏数据库,也无法保证没有其他方法可以恢复数据。此外,您将不知道是否成功。 - Solarflare
1
唯一的错误可能是数据库是否能够正常工作(或者只是看起来正常)。或者,如果崩溃没有某些潜在原因(例如损坏的 RAM 或 HDD)。为了提高成功率,您可以雇用某人为您完成此操作。但在您的情况下,似乎不是生产站点或重要数据,重新安装您的 wp 主题可能会修复它。所以,庆幸它现在发生而不是以后。使用此提示进行备份(有 WordPress 插件可供使用)。顺便说一句,任何您雇用的人都会问的第一件事是:“您的备份有多久了”。 - Solarflare
显示剩余2条评论
1个回答

20

最近在使用MAMP进行本地开发时遇到了类似问题,日志中包含“数据库没有正常关闭”的错误消息以及之后的类似错误消息和建议。以下是解决该问题的步骤:

  1. 停止MAMP中的服务器
  2. 导航至您的WP DB的.idb文件-如果使用MAMP,应该在类似于~/Library/Application Support/appsolute/MAMP PRO/db/mysql56/[yourdbname]/的位置
  3. 将.bk(或任何无法识别的扩展名)添加到.idb文件名的末尾
  4. 启动MAMP中的服务器。如果查看日志,您会看到许多与找不到.idb文件相关的错误消息,但至少MySQL应该可以启动。
  5. 停止MAMP中的服务器
  6. 从.idb文件名中删除.bk(或其他您使用的名称)
  7. 在MAMP中启动服务器-此时应该一切都准备好了。

由于还没有对数据库进行太多工作,所以愿意丢失数据甚至重新安装MAMP;如果您的情况不同,则最好首先将db目录备份到.zip文件中,以便稍后尝试其他方法。

希望这能帮助到您。

更新:
发现用以下步骤替换第3步和第6步更快:
3. 在方便的地方创建一个临时文件夹;选择所有的.idb文件并将它们移动到该文件夹中。
6. 将文件从第2步的原始文件夹移动回原始文件夹。 ....


2
不必重命名.idb文件,您可以将文件暂时移出文件夹,并在第6步放回。如果您有10个以上的表格。 :) - Cyber
1
这对我没有起作用,但是这个链接解决了问题:http://blog.ign.uy/2017/how-to-fix-mysql-not-starting-on-mamp-pro - Martijn La Feber
存在 .ibd 文件,但不存在 .idb 文件。 - Flame

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接