Mysql启动不了



2015-08-04 15:42:30 11727 [Note] InnoDB: Database was not shutdown normally!
2015-08-04 15:42:30 11727 [Note] InnoDB: Starting crash recovery.
2015-08-04 15:42:30 11727 [Note] InnoDB: Reading tablespace information from the .ibd files...
2015-08-04 15:42:30 11727 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace test2/p
roduct uses space ID: 9 at filepath: ./test2/product.ibd. Cannot open tablespace test1/product which uses space ID: 9 a
t filepath: ./test1/product.ibd
2015-08-04 15:42:30 7ff694b44720  InnoDB: Operating system error number 2 in a file operation.
InnoDB: The error means the system cannot find the path specified.
InnoDB: If you are installing InnoDB, remember that you must create
InnoDB: directories yourself, InnoDB does not create them.
InnoDB: Error: could not open single-table tablespace file ./test1/product.ibd

问题:
./test1/product.ibd 不存在了,所以数据库无法启动
解决:
vi my.cnf
innodb_force_recovery = 1


mysql> use test2


mysql> show tables;
+-----------------+
| Tables_in_test2 |
+-----------------+
| product         |
+-----------------+

drop tale product         ;

该参数各值含义如下:


默认为0,表示当需要恢复时执行所有的恢复操作(即校验数据页/purge undo/insert buffer merge/rolling back&forward).当不能进行有效的恢复操作时,mysql有可能无法启动,并记录下错误日志.
innodb_force_recovery可以设置为0-6,大的数字包含前面所有数字的影响.
当设置参数值大于0后,可以对表进行select,create,drop操作,但insert,update或者delete这类操作是不允许的.
1.(SRV_FORCE_IGNORE_CORRUPT):     忽略检查到的corrupt页.
2.(SRV_FORCE_NO_BACKGROUND):    阻止主线程的运行,如主线程需要执行full purge操作,会导致crash.
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):    不执行前滚的操作.


undo问题需要设置innodb_force_recovery 为6,此时,无法执行写操作,应尽快将数据dump出来,修改innodb_force_recovery = 0,重启服务,创建新表后,把数据倒回去
6:数据库处于只读模式

停止mysql服务,将目录下的ib_logfile*文件全部删除掉,重新启动mysql服务


请使用浏览器的分享功能分享到微信等