且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-01-31 22:38:06

前言:这听起来很糟糕,但是在执行操作之前,请务必先阅读此答案中的所有内容.花费时间不能使事情变得更糟.阅读每个步骤&希望这一点足够清楚,让您可以关注&重新启动MAMP Pro中的MySQL数据库服务器并重新运行.

PREFACE: This sounds bad, but please be sure to read everything in this answer before acting. You can’t break things worse by taking your time. Read each step & hopefully this will be clear enough for you to follow & get your MySQL database server in MAMP Pro up and running again.

所以,看来您的InnoDB数据库崩溃了.不是应用程序本身.密钥在日志中:

So, it seems like your InnoDB databases crashed. Not the app itself. The key is here in the log:

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:

And it looks like you are using MAMP PRO over here:

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

问题是,您是否有MAMP Pro数据库的备份?通过mysqldump还是其他?您的MAMP安装中是否还有其他InnoDB数据库?

So the question is, do you have a backup of the MAMP Pro databases? Either via mysqldump or something else? Do you have other InnoDB databases in your MAMP install?

此外,您说您能够运行mysqldump,但实际上不可能发生数据库崩溃.因此,我假设当您运行mysqldump时,这是系统上另一个单独的MySQL安装. MySQL二进制文件(例如MAMP或MAMP Pro中的mysqldump)与系统范围的mysqldump不同.他们是两个100%不同的安装.您可以通过键入以下命令来检查正在使用哪个mysqldump:

Also, you say you were able to run mysqldump, but it’s really not possible of the database crashed. So I am assuming when you ran mysqldump that was another, separate install of MySQL on your system. The MySQL binaries such as mysqldump in MAMP or MAMP Pro are not the same as the systemwide mysqldump. They are two 100% different installs. You can check which mysqldump is being used by typing in this command:

which mysqldump

查看您认为所使用内容的完整路径. mysqldump和其他相关二进制文件的MAMP安装位于此处:

To see the full path of what you believe you were using. The MAMP install of mysqldump—and other related binaries—is located here:

/Applications/MAMP/Library/bin/

直接运行而不修改您的$PATH值(完全是另一回事)就是这样运行:

And to run it directly without modifying your $PATH value (a whole other thing) is to run it like this:

/Applications/MAMP/Library/bin/mysqldump

请仔细阅读:请注意,我在下面为您提供的建议是我提出的应对这种情况的所有方式.如果InnoDB数据库不重要,请执行我的第一个建议,丢弃InnoDB特定的DB文件.如果您有mysqldump备份,请执行相同的操作,但是要恢复mysqldump备份.

PLEASE READ CAREFULLY: Please note the advice I am giving you below is me presenting every way I would deal with a situation like this. If the InnoDB database is not important, just do my first suggestion of trashing the InnoDB specific DB files. If you have a mysqldump backup, do the same thing but recover the mysqldump backup.

此外,InnoDB不是默认存储引擎.您必须竭尽所能进行设置.默认值为MyISAM.在MySQL中创建的任何新数据库都将是MyISAM.因此,这将为您提供帮助.您需要考虑一下哪些数据库设置了InnoDB存储引擎.如果您说您有25个,但只有1个拥有InnoDB,这是简单的解决方案.但是,如果您有25个数据库,则应该养成定期进行mysqldump备份的习惯.如果您有备份,这将是一件令人头疼的事,但很容易解决.

Also, InnoDB is not a default storage engine. You have to go out of your way to set that. The default is MyISAM. Any new DB created in MySQL will be MyISAM. So this will help you. You need to put on your thinking cap an figure out which databases have InnoDB storage engines set. If you say you have 25 but only 1 has InnoDB, easy solution. But also if you have 25 databases, you should get into the habit of making regular mysqldump backups. If you had backups, this would be a headache but a straight forward thing to solve.

一个选项:删除损坏的InnoDB内容&从mysqldump备份中恢复.

ONE OPTION: Delete the corrupted InnoDB stuff & recover from a mysqldump backup.

如果我是我,要做的第一件事就是备份/Library/Application Support/appsolute/MAMP PRO/db/中的mysql目录,以便至少可以备份损坏的文件,以防万一.

The first thing I would do if I were you is backup the mysql directory in /Library/Application Support/appsolute/MAMP PRO/db/ so you can at least have a backup of the corrupted files just in case.

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

Then I would delete the following files:

/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数据库都将处于僵尸"状态.您应该删除那些数据库&从备份重新创建.或从头开始.

Those are InnoDB specific files. Delete them and then attempt to start MAMP again. It should come up. But any InnoDB database in MAMP will be in some "zombie" state. You should delete those databases & recreate from backup. Or from scratch if you can.

另一个选项:尝试启动MySQL服务器&再次使用innodb_force_recovery运行.

ANOTHER OPTION: Try to get the MySQL server up & running again with innodb_force_recovery.

现在,您需要立即恢复该数据库时,可以尝试设置

Now on the offhand chance you need to recover that DB, you can run attempt to set a innodb_force_recovery as described here.

对于MAMP Pro,看来您可以按照以下说明编辑MySQL配置文件:

For MAMP Pro it seems you can edit your MySQL configuration file as per these instructions:

  1. 启动MAMP Pro.
  2. 如果MAMP Pro服务器正在运行,请停止它.
  3. 选择文件->编辑模板-> MySQL my.cnf
  4. 出现一个编辑器窗口.
  5. 如果出现警告消息,请单击确定"确认.
  6. 找到"[mysqld]"部分
  7. 在本节的最后一行下面添加以下行:innodb_force_recovery = 1
  1. Start MAMP Pro.
  2. Stop the MAMP Pro server if it is running.
  3. Select File -> Edit Template -> MySQL my.cnf
  4. An editor window appears.
  5. If a warning message appears confirm with OK.
  6. Find the section "[mysqld]"
  7. Beneath the last line of this section add this line: innodb_force_recovery = 1

并且如MySQL文档所述 ,这严格是为了使数据库正常运行,因此您可以通过mysqldump进行备份:

And as the MySQL documentation explains, this is strictly to get the database up and running so you can make a backup via mysqldump:

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

In such cases, use the innodb_force_recovery option to force the InnoDB storage engine to start up while preventing background operations from running, so that you can dump your tables.

现在innodb_force_recovery大约有6个不同的值,但是您现在真的应该只尝试使用1.如果您想尝试6种,请按以下步骤进行操作:

Now there are about 6 different values for innodb_force_recovery but you should really only attempt with 1 for now. If you want to attempt each of the 6, here is a breakdown:

1(SRV_FORCE_IGNORE_CORRUPT)

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

Lets the server run even if it detects a corrupt page. Tries to make SELECT * FROM tbl_name jump over corrupt index records and pages, which helps in dumping tables.

2(SRV_FORCE_NO_BACKGROUND)

防止主线程和所有清除线程运行.如果一个 清除操作期间将发生崩溃,此恢复值 防止它.

Prevents the master thread and any purge threads from running. If a crash would occur during the purge operation, this recovery value prevents it.

3(SRV_FORCE_NO_TRX_UNDO)

崩溃恢复后不运行事务回滚.

Does not run transaction rollbacks after crash recovery.

4(SRV_FORCE_NO_IBUF_MERGE)

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

Prevents insert buffer merge operations. If they would cause a crash, does not do them. Does not calculate table statistics.

5(SRV_FORCE_NO_UNDO_LOG_SCAN)

启动数据库时不查看撤消日志:InnoDB对待 甚至是未完成的交易.

Does not look at undo logs when starting the database: InnoDB treats even incomplete transactions as committed.

6(SRV_FORCE_NO_LOG_REDO)

不进行与恢复有关的重做日志前滚.

Does not do the redo log roll-forward in connection with recovery.

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

With this value, you might not be able to do queries other than a basic SELECT * FROM t, with no WHERE, ORDER BY, or other clauses. More complex queries could encounter corrupted data structures and fail.

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

If corruption within the table data prevents you from dumping the entire table contents, a query with an ORDER BY primary_key DESC clause might be able to dump the portion of the table after the corrupted part.

如果您碰巧要启动并运行数据库,然后可以执行mysqldump,那么恭喜您!你没事!***的下一步是

If you happen to get the database up and running and then can do a mysqldump then congratulations! You are in the clear! The best next steps is to

  1. 停止MySQL数据库服务器
  2. 从MySQL配置中删除innodb_force_recovery选项,以便数据库服务器可以正常运行.
  3. 重新启动MySQL数据库服务器.
  4. 从服务器删除损坏的MySQL数据库(不要删除转储文件!这是您的备份!)
  5. 创建一个要恢复的新数据库.
  6. mysqldump备份导入新数据库.
  1. Stop the MySQL database server
  2. Remove the innodb_force_recovery option from the MySQL config so the database server can operate normally.
  3. Restart the MySQL database server.
  4. Delete the corrupted MySQL database from the server (Don’t delete the dump file! That is your backup!)
  5. Create a new database you want to recover.
  6. Import the mysqldump backup into the new database.

您应该完成.