WP-Mix

A fresh mix of code snippets and tutorials

Fix Database Won’t Start Error for MAMP Pro

I use MAMP Pro for some of my local pet projects and development. Normally it works great, but the other day I couldn’t get MySQL started. It kept crashing during startup. This post explains the related errors and how I managed to resolve the issue and get MAMP working again.

The Error

Here are the associated errors and infos recorded in the MAMP log file:

[ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace perishable/accounts uses space ID: 1 at filepath: ./perishable/accounts.ibd. Cannot open tablespace mysql/innodb_table_stats which uses space ID: 1 at filepath: ./mysql/innodb_table_stats.ibd

Operating system error number 2 in a file operation. The error means the system cannot find the path specified. If you are installing InnoDB, remember that you must create directories yourself, InnoDB does not create them.

Error: could not open single-table tablespace file ./mysql/innodb_table_stats.ibd

We do not continue the crash recovery, because the table may become corrupt if we cannot apply the log records in the InnoDB log to it. To fix the problem and start mysqld:

1) If there is a permission problem in the file and mysqld cannot open the file, you should modify the permissions.
2) If the table is not needed, or you can restore it from a backup, then you can remove the .ibd file, and InnoDB will do a normal crash recovery and ignore that table.
3) If the file system or the disk is broken, and you cannot remove the .ibd file, you can set innodb_force_recovery > 0 in my.cnf and force InnoDB to continue crash recovery here.

I tried several times to start the service, restart MAMP, restart the computer, etc., but nothing seemed to work. The MySQL server would not start.

The Solution

To get MySQL started and working again, open MAMP and go to File > Edit Template > MySQL > and select your MySQL version. That will open the MySQL configuration file, where you can locate the following line:

#innodb_force_recovery = 2

Uncomment the line, and change the value to 1, so it looks like this:

innodb_force_recovery = 1

Then restart MySQL and try again. If it works, you can comment out (disable) the line by prepending a pound sign # (hashtag whatever you want to call it). For more information about what innodb_force_recovery is doing, check out the MySQL documentation.

Note: This technique is known to work with MAMP Pro, but it also may work on the free version of MAMP. Good luck! :)

★ Pro Tip:

Banhammer ProBlackhole ProBBQ Pro