今天不知道什么原因,有台服务器挂了,SA重启了服务器。很快就有人跟我说有两个测试数据库访问不了,一看没起来,首先想到的这两个数据库应该加到自动启动里面,然后mysqld_safe居然没起来,查看mysqld.log,错误为:
090909 10:33:36 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...
090909 10:33:36 InnoDB: Starting log scan based on checkpoint at
InnoDB: log sequence number 444 2484334770.
InnoDB: Doing recovery: scanned up to log sequence number 444 2489577472
InnoDB: Doing recovery: scanned up to log sequence number 444 2494820352
InnoDB: Doing recovery: scanned up to log sequence number 444 2500063232
InnoDB: Doing recovery: scanned up to log sequence number 444 2504268800
InnoDB: 1 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 936621 row operations to undo
InnoDB: Trx id counter is 1 822287872
090909 10:33:37 InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 0 InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 2447757.
InnoDB: You may have to recover from a backup.
mysql想重做服务器挂时没来得及更新到磁盘的操作,但是磁盘磁盘上有个数据文件出错了,以前还没遇到过,google了一下,发生相同的错误的人还真不少。没办法,只有强制恢复了,设置innodb force recovery。mysql起来了,数据没什么大问题。
下面说下innodb force recovery的6种设置:
1. innodb force recovery=1,即使发现了损坏页面也继续让服务器继续运行,这个选项对于备份或者转存当前数据尤为有用
2. innodb force recovery=2,阻止恢复主线程的运行,如果清除操作会导致服务器挂掉
3. innodb force recovery=3,恢复后不回滚事务
4. innodb force recovery=4,如果插入到缓冲区的合并操作会导致系统崩溃,将不会被执行
5. innodb force recovery=5,启动数据库时,忽略撤消日志
6. innodb force recovery=6,启动数据库时,忽略与恢复相关的前滚日志
这个办法只适用与测试库或者不那么敏感的数据库,对于线上库应该立即将服务连向镜像库,恢复产品库,然后将服务连上产品库