1. Add the following code to the MySQL configuration file my.cnf:
[mysqld]innodb_force_recovery=1 #可以设置1-6innodb_purge_thread=0 #如果上边的配置值大于1,此处就要设置为0,否则就会出现InnoDB: Waiting for the background threads to start的错误
Parameters for the configuration file: Innodb_force_recovery
innodb_force_recovery影响整个InnoDB存储引擎的恢复状况。默认为0,表示当需要恢复时执行所有的恢复操作(即校验数据页/purge?undo/insert?buffer?merge/rolling?back&forward),当不能进行有效的恢复操作时,mysql有可能无法启动,并记录错误日志;innodb_force_recovery可以设置为1-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):不执行前滚的操作。
2. Restart the database and log in to MySQL backup data
mysqldump -uroot -p --all-databases> back.sql
3. Comment out the two lines of code previously added in the my.cnf file, delete all files in the/var/lib/mysql/directory, restart MySQL, and reboot successfully. 4, re-execute the MySQL security script mysql_secure_installation, set the root login password, and then log in to MySQL for database recovery.
source?back.sql;
Innodb_force_recovery forced repair of MySQL exception shutdown