MySQL 无法启动修复



$ ./mysqld

2017-03-23 08:42:32 1358 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace mysql/slave_relay_log_info uses space ID: 3 at filepath: ./mysql/slave_relay_log_info.ibd. Cannot open tablespace shop/admin which uses space ID: 3 at filepath: ./shop/admin.ibd
2017-03-23 08:42:32 7fffad71c3c0  InnoDB: Operating system error number 2 in a file operation.


It means one of your tables is corrupted. Weirdly this has happened to frequently upon a machine crash. This is how I fixed it:

  1. open my.cnf (in MAMP > File > Edit Template > MySQL)
  2. add the line: innodb_force_recovery = 1
  3. save and start servers

The table will likely still be broken, but mysql should start. It means you may have to replace your table: wp_term_taxonomy

Note: If innodb_force_recovery = 1 does not work, try going up in numbers: innodb_force_recovery = 2 (etc) But tread carefully. Here’s MySQL’s warning on this setting:



查看 MySQL 配置文件路径方法:mysql --help | grep my.cnf

$ ./mysql --help | grep my.cnf

                      order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /Applications/MAMP/conf/my.cnf ~/.my.cnf