관리자 글쓰기
[mysql5.6] InnoDB강제로복구
2016. 8. 31. 10:17 - 미나리다

mysql 5.6 서버가 실행되지않아 에러로그파일을 보니 


2016-08-30 13:56:29 3376 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace feet/piwik_site_url uses space ID: 77 at filepath: .\feet\piwik_site_url.ibd. Cannot open tablespace noongaru/piwik_site_url which uses space ID: 77 at filepath: .\noongaru\piwik_site_url.ibd

InnoDB: Error: could not open single-table tablespace file .\noongaru\piwik_site_url.ibd

InnoDB: We do not continue the crash recovery, because the table may become

InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it.

InnoDB: To fix the problem and start mysqld:

InnoDB: 1) If there is a permission problem in the file and mysqld cannot

InnoDB: open the file, you should modify the permissions.

InnoDB: 2) If the table is not needed, or you can restore it from a backup,

InnoDB: then you can remove the .ibd file, and InnoDB will do a normal

InnoDB: crash recovery and ignore that table.

InnoDB: 3) If the file system or the disk is broken, and you cannot remove

InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf

InnoDB: and force InnoDB to continue crash recovery here.

2016-08-30 13:56:29 3376 [Note] InnoDB: innodb_force_recovery was set to 1. Continuing crash recovery even though we cannot access the .ibd file of this table.

2016-08-30 13:56:29 3376 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace feet/piwik_user uses space ID: 74 at filepath: .\feet\piwik_user.ibd. Cannot open tablespace noongaru/piwik_user which uses space ID: 74 at filepath: .\noongaru\piwik_user.ibd

InnoDB: Error: could not open single-table tablespace file .\noongaru\piwik_user.ibd

InnoDB: We do not continue the crash recovery, because the table may become

InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it.

InnoDB: To fix the problem and start mysqld:

InnoDB: 1) If there is a permission problem in the file and mysqld cannot

InnoDB: open the file, you should modify the permissions.

InnoDB: 2) If the table is not needed, or you can restore it from a backup,

InnoDB: then you can remove the .ibd file, and InnoDB will do a normal

InnoDB: crash recovery and ignore that table.

InnoDB: 3) If the file system or the disk is broken, and you cannot remove

InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf

InnoDB: and force InnoDB to continue crash recovery here.


과 같은 에러가 나오며 실행이되지않고있었습니다 ㅜㅜ 확인해보니 innodb테이블쪽에 깨진듯하여


InnoDB: Attempted to open a previously opened tablespace 문구를 찾아보니 mysql 설정파일에서 

innodb 강제복구 옵션이있네요


my.cnf 에서 


[mysqld]

innodb_force_recovery = 4   <--으로 설정해준뒤 저장하여 mysql시작시켜주면 됩니다)



옵션값은 0~6까지있는데 0보다 큰 값으로 설정되어있으면 INSERT, UPDATE , DELETE 연산을 하지못한다고하며 큰값으로 설정될수록 아래숫자의 사항을 포함하게된다고합니다. 옵션값을 4로한다면 깨진 페이지에 잃어버린 데이터에대해서는 상대적으로 안전하다고함


옵션값 1 (SRV_FORCE_IGNORE_CORRUPT) : 손상된 페이지가 발견되어도 무시하고 mysql을 가동한다 가동이되면 테이블을 덤프하여 복구시키거나 다른데이터베이스로 이전하는것이 좋다 (손상된 레코드와 페이지는 모두 건너뛰게됨으로 데이터를 잃게됨)


옵션값 2 (SRV_FORCE_NO_BACKGROUND) : 메인 쓰레드가 구동되지 못하도록 한다. 만일 퍼지 연산 (purge operation)이 진행되는 동안 크래시가 발생한다면, 이 복구 값은 퍼지 연산이 실행되는 것을 막게 된다.


온션값 3 (SRV_FORCE_NO_TRX_UNDO) : mysql종료하던 시점에 진행중인 트랜잭션이있다면 mysql 단순히 그 연결을 끊는다. 다시실행후 innodb엔진이 롤백을 실행하는데 만약 데이터가 손상된경우 롤백을 실행할수없기때문에 이경우 사용되는 복구모드이다.


옵션값 4 (SRV_FORCE_NO_IBUF_MERGE) :  INSERT, UPDATE , DELETE  연산자를 실행하지 않도록 한다. 테이블 통계값을 계산하지 않도록 한다.


옵션값 5 (SRV_FORCE_NO_UNDO_LOG_SCAN) :데이터베이스를 시작할 때 운도 로그 (undo log)를 검사하지 않는다: InnoDB는 완벽하지 않은 트랜젝션도 실행된 것으로 다루게 된다.


옵션값 6 (SRV_FORCE_NO_LOG_REDO) : mysql이 재시작전 가장뒤에 발생한 체크포인트 이후 모든 트랜잭션을 버리고 복구시키는 모드이다 복구 연결에서 로그 롤-포워드 (roll-forward)를 실행하지 않고 강제복구한다


설정한 숫자가 커질수록 손실되는 데이터가 많아지므로 되도록 강제복구모드 설정을 낮은숫자 1 -> 2 -> 3 -> 4 -> 5 -> 6  순으로 시도해보는 것이 좋습니다!!!