MySQL 无法启动修复

mysql-recovery

报错如下

$ ./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:https://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html

(参考链接:http://stackoverflow.com/a/40919026)

另外补充

查看 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

若不存在创建一个文件即可。