MAMP PRO崩溃;MySQL无法在重新启动时启动

4
今天工作的时候,我的电脑突然冻结/崩溃了。重新启动后,MAMP拒绝启动mysql,我无法弄清原因。 绝对没有其他mysql进程在运行;我已经检查过多次。 因此,“killall -9 mysqld”不是解决方案。实际上,我已经完全重新安装了MAMP。
这似乎是我的MySQL日志中最重要的部分,但我并不太擅长阅读这些内容,所以也许答案就在我面前。
140527 15:06:58 mysqld_safe Starting mysqld daemon with databases from /Library/Application Support/appsolute/MAMP PRO/db/mysql
140527 15:06:58 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
140527 15:06:58 [Warning] Setting lower_case_table_names=2 because file system for /Library/Application Support/appsolute/MAMP PRO/db/mysql/ is case insensitive
140527 15:06:58 [Note] Plugin 'FEDERATED' is disabled.
140527 15:06:58 InnoDB: The InnoDB memory heap is disabled
140527 15:06:58 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140527 15:06:58 InnoDB: Compressed tables use zlib 1.2.3
140527 15:06:58 InnoDB: Initializing buffer pool, size = 128.0M
140527 15:06:58 InnoDB: Completed initialization of buffer pool
140527 15:06:58 InnoDB: highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 791075520
140527 15:06:58  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 791076717
InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 8402.
InnoDB: You may have to recover from a backup.
140527 15:06:58  InnoDB: Page dump in ascii and hex (16384 bytes):
 len 16384; hex ....
InnoDB: End of page dump
140527 15:06:58  InnoDB: Page checksum 3802906200, prior-to-4.0.14-form checksum 786607151
InnoDB: stored checksum 3802906200, prior-to-4.0.14-form stored checksum 1787456768
InnoDB: Page lsn 0 791046088, low 4 bytes of lsn at page end 790720183
InnoDB: Page number (if stored to page already) 8402,
InnoDB: space id (if created with >= MySQL-4.1.1 and stored already) 0
InnoDB: Page may be an insert undo log page
InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 8402.
InnoDB: You may have to recover from a backup.
InnoDB: It is also possible that your operating
InnoDB: system has corrupted its own file cache
InnoDB: and rebooting your computer removes the
InnoDB: error.
InnoDB: If the corrupt page is an index page
InnoDB: you can also try to fix the corruption
InnoDB: by dumping, dropping, and reimporting
InnoDB: the corrupt table. You can use CHECK
InnoDB: TABLE to scan your table for corruption.
InnoDB: See also http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
InnoDB: Ending processing because of a corrupt database page.
140527 15:06:58  InnoDB: Assertion failure in thread 140735261836048 in file buf0buf.c line 3619
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
19:06:58 UTC - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed, 
something is definitely wrong and this may fail.

key_buffer_size=16777216
read_buffer_size=262144
max_used_connections=0
max_threads=151
thread_count=0
connection_count=0
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 134084 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0 thread_stack 0x40000
0   mysqld                              0x000000010028081c my_print_stacktrace + 44
1   mysqld                              0x0000000100021624 handle_fatal_signal + 692
2   libsystem_platform.dylib            0x00007fff91e625aa _sigtramp + 26
3   ???                                 0x0000000000000000 0x0 + 0
4   libsystem_c.dylib                   0x00007fff9355bb1a abort + 125
5   mysqld                              0x00000001002b30af buf_page_io_complete + 959
6   mysqld                              0x00000001002b9892 buf_read_page_low + 610
7   mysqld                              0x00000001002b9fa5 buf_read_page + 85
8   mysqld                              0x00000001002b4431 buf_page_get_gen + 673
9   mysqld                              0x000000010034fdd5 trx_undo_lists_init + 373
10  mysqld                              0x0000000100348e2e trx_rseg_mem_create + 334
11  mysqld                              0x0000000100348fed trx_rseg_list_and_array_init + 157
12  mysqld                              0x000000010034a147 trx_sys_init_at_db_start + 215
13  mysqld                              0x000000010033eafd innobase_start_or_create_for_mysql + 5805
14  mysqld                              0x00000001003114c1 _ZL13innobase_initPv + 1473
15  mysqld                              0x0000000100027028 _Z24ha_initialize_handlertonP13st_plugin_int + 104
16  mysqld                              0x000000010017f0f1 _ZL17plugin_initializeP13st_plugin_int + 97
17  mysqld                              0x0000000100181810 _Z11plugin_initPiPPci + 3776
18  mysqld                              0x00000001000ccce5 _Z11mysqld_mainiPPc + 10405
19  mysqld                              0x0000000100001804 start + 52
20  ???                                 0x000000000000000a 0x0 + 10
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
140527 15:06:58 mysqld_safe mysqld from pid file /Applications/MAMP/tmp/mysql/mysql.pid ended

当我尝试进行数据库转储时,我得到了如下错误:(编辑:我已经解决了这个问题)
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when trying to connect

我刚刚发布了一个答案。这听起来很糟糕,但我有一些提示。但是我对“尝试进行数据库转储时出现困惑:(编辑:我已经解决了这部分)”感到困惑。所以你现在有数据库的mysqldump吗? - Giacomo1968
@JakeGould,mysqldump无法连接,因为mysqld未运行。 - Bill Karwin
1
@BillKarwin 那么“I got this part of it fixed”的意思是什么? - Giacomo1968
@JakeGould,我不知道,OP必须澄清。但是如果mysqld有损坏的页面,它将继续崩溃。 - Bill Karwin
在我重新启动mysql后,我成功地获得了一个mysql转储文件。我还复制了db文件夹中的所有ib文件和dbs的内容。此外,我还有一周前的Time Machine备份,包括整个系统的所有内容。 - thesublimeobject
我还有一个(虽然是一周前的)整个系统的时间机器备份。这可能是你最好的解决方案。 - Giacomo1968
2个回答

20

前言:听起来很糟糕,但在采取行动之前,请务必阅读此答案中的所有内容。您不会因为花费更多时间而使事情变得更糟。请逐步阅读,希望这些步骤足够清晰,让您能够跟随并重新启动MAMP Pro中的MySQL数据库服务器。

所以,似乎是您的InnoDB数据库崩溃了,而不是应用程序本身。关键在于日志中的这里:

140527 15:06:58 InnoDB: highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 791075520
140527 15:06:58  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 791076717
InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 8402.
InnoDB: You may have to recover from a backup.

看起来您正在使用MAMP PRO:

/Library/Application Support/appsolute/MAMP PRO/db/mysql

所以问题是,您是否有MAMP Pro数据库的备份?通过mysqldump或其他方式?您在MAMP安装中是否有其他InnoDB数据库?
另外,您说您能够运行mysqldump,但如果数据库崩溃,这是不可能的。因此,我假设当您运行mysqldump时,那是您系统上的另一个单独的MySQL安装。 MAMP或MAMP Pro中的MySQL二进制文件(例如mysqldump)与系统范围内的mysqldump不同。它们是两个完全不同的安装。您可以通过输入此命令来检查使用哪个mysqldump
which mysqldump

为了查看你认为正在使用的完整路径。MAMP安装的mysqldump和其他相关二进制文件位于此处:
/Applications/MAMP/Library/bin/

如果不修改您的$PATH值(另一件事情),直接运行它的方法是这样的:

/Applications/MAMP/Library/bin/mysqldump

请仔细阅读:以下是我处理这种情况的所有方法。如果InnoDB数据库不重要,请直接按照我的第一个建议删除InnoDB特定的DB文件。如果您有mysqldump备份,请执行相同的操作,但恢复mysqldump备份。另外,InnoDB不是默认存储引擎。您需要费点心思去设置它。默认为MyISAM。MySQL中创建的任何新DB都将是MyISAM。所以这会帮助您。您需要戴上思考帽子并找出哪些数据库已设置了InnoDB存储引擎。如果您说您有25个数据库,但只有1个具有InnoDB,则很容易解决。但是,如果您有25个数据库,您应该养成定期进行mysqldump备份的习惯。如果有备份,这将是一个头痛但简单的问题解决方案。
一个选择:删除损坏的InnoDB内容并从mysqldump备份中恢复。

如果我是你,首先要做的事情就是备份 /Library/Application Support/appsolute/MAMP PRO/db/ 目录下的 mysql 文件夹,这样即使文件损坏也能有备份。

然后,我会删除以下文件:

/Library/Application Support/appsolute/MAMP PRO/db/mysql/ib_logfile0
/Library/Application Support/appsolute/MAMP PRO/db/mysql/ib_logfile1
/Library/Application Support/appsolute/MAMP PRO/db/mysql/ibdata1

这些是InnoDB特定的文件。删除它们,然后尝试重新启动MAMP。它应该会启动。但是MAMP中的任何InnoDB数据库都将处于某种“僵尸”状态。您应该删除这些数据库并从备份重新创建。如果可以的话,也可以从头开始创建。
另一个选择:尝试使用innodb_force_recovery使MySQL服务器再次运行。
现在,如果您需要恢复该数据库,可以按照此处描述的方式尝试设置innodb_force_recovery
对于MAMP Pro,似乎可以根据这些说明编辑MySQL配置文件:
  1. 启动MAMP Pro。
  2. 如果MAMP Pro服务器正在运行,请停止它。
  3. 选择 文件 -> 编辑模板 -> MySQL my.cnf
  4. 编辑窗口将出现。
  5. 如果出现警告消息,请确认点击“确定”。
  6. 找到“[mysqld]”部分。
  7. 在该部分的最后一行下方添加此行:innodb_force_recovery = 1

正如MySQL文档所解释的那样,这仅是为了使数据库运行起来,以便您可以通过mysqldump进行备份:

在这种情况下,使用innodb_force_recovery选项强制 InnoDB存储引擎启动,同时防止后台操作运行,以便您可以转储表。

现在有大约6个不同的innodb_force_recovery值,但现在您应该只尝试1。如果要尝试每个6个值,则应该这样做:

1 (SRV_FORCE_IGNORE_CORRUPT)

即使检测到损坏的页面,也允许服务器运行。尝试使SELECT * FROM tbl_name跳过损坏的索引记录和页面,有助于转储表。

2 (SRV_FORCE_NO_BACKGROUND)

防止主线程和任何清除线程运行。如果在清除操作期间发生崩溃,此恢复值将防止其发生。

3 (SRV_FORCE_NO_TRX_UNDO)

在崩溃恢复后不执行事务回滚。

4 (SRV_FORCE_NO_IBUF_MERGE)

防止插入缓冲区合并操作。如果它们会导致崩溃,则不执行它们。不计算表统计信息。

5 (SRV_FORCE_NO_UNDO_LOG_SCAN)

启动数据库时不查看撤消日志:InnoDB将即使是不完整的事务视为已提交。

6 (SRV_FORCE_NO_LOG_REDO)

在恢复期间不进行重做日志向前滚动。

使用此值,您可能无法执行除基本的SELECT * FROM t之外的查询,没有WHEREORDER BY或其他子句。更复杂的查询可能会遇到损坏的数据结构并失败。

如果表数据中的损坏阻止您转储整个表内容,则具有ORDER BY primary_key DESC子句的查询可能能够转储损坏部分之后的表部分。

如果您已经成功运行数据库并可以执行mysqldump,那么恭喜您!您已经解决了问题!下一步最好的操作是:
  1. 停止MySQL数据库服务器
  2. 从MySQL配置中删除innodb_force_recovery选项,以便数据库服务器可以正常运行。
  3. 重新启动MySQL数据库服务器。
  4. 从服务器上删除损坏的MySQL数据库(不要删除备份文件!那是您的备份!)
  5. 创建您想要恢复的新数据库。
  6. mysqldump备份导入新数据库。
完成后您应该就完成了。

在我离开之前还有一个问题。继续上面的话题,我需要删除所有数据库吗?如果需要,那么我的mysqldump会重新创建每个数据库吗?我问这个问题是因为你经常提到创建或恢复单个数据库,但我大约有25个数据库。//非常感谢您的帮助。您列出的所有内容基本上都是我在网上找到的更简洁易懂的信息的综合。//编辑:这也应该回答上面的问题。 - thesublimeobject
1
@JakeGould...最终我把这个弄好了,这很大程度上要归功于你。我真的非常非常非常感激你的帮助。 - thesublimeobject
1
奇怪的是,我根本无法让sqldump工作。我在innodb恢复之前和之后都尝试过。它只会生成一个非常小的文件,其中不包含任何我的数据库,好像它不知道它们的存在(虽然我认为MAMP有一个完全不同的mysql安装,这可能是我需要解决的问题)。因此,最终我使用了innodb恢复,然后从phpmyadmin导出了所有的数据库,并确保勾选了“添加创建数据库”,然后我从mysql文件夹中删除了所有内容并重新导入了所有内容。 - thesublimeobject
删除 /Library/Application Support/appsolute/MAMP PRO/db/mysql/ 目录下的文件(答案中提到的3个文件)以及我之前创建的数据库文件(旧数据库),这解决了我的问题。在多次重新安装 MAMP 后,我认为是 mySQL 加载或同步旧的数据库文件出了问题。感谢上帝,因为我不再使用它们。 - Telvin Nguyen
1
我已经试了几个小时来解决这个问题。最终删除以下文件解决了问题:/Library/Application Support/appsolute/MAMP PRO/db/mysql/ib_logfile0 /Library/Application Support/appsolute/MAMP PRO/db/mysql/ib_logfile1 /Library/Application Support/appsolute/MAMP PRO/db/mysql/ibdata1谢谢。 - el3ati2
显示剩余7条评论

0

你的ibdata1文件中的一个页面在从磁盘读取时未通过校验和测试,这会导致MySQL自行崩溃。他们不希望您意外读取已知为损坏的数据,也不希望冒着损坏实例中的任何其他数据的风险。

您可以在此处阅读有关恢复剩余数据的提示:恢复Innodb表损坏

innodb_force_recovery可能有助于解决问题,也可能无法解决。对损坏页面的任何读取都将再次导致服务器崩溃。错误提示表明,损坏的页面位于更改缓冲区中,该缓冲区由后台线程在启动时立即处理。innodb_force_recovery=4或更高版本将防止读取更改缓冲区。

如果您有数据库备份,删除ibdata1文件、ib_log*文件和其他.ibd文件,然后恢复备份可能会更简单。您还可以回放二进制日志进行时间点恢复


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