|
解決方法To resolve the problem, it is recommended that you recover the InnoDB engine. However, note that the recovery may fail. In this case, it is recommended to restore databases from backup. To recover an InnoDB engine, it's recommended to dump all databases, remove the databases and corrupted InnoDB files, recreate a base mysql engine, and restore the databases from dump.
Use the following instructions to conduct recovery:
1) Stop mysqld and backup all database files located in /var/lib/mysql/:
~# /etc/init.d/mysqld stop
~# mkdir /root/mysql_backup
~# cp -r /var/lib/mysql/* /root/mysql_backup/
2) Add option innodb_force_recovery into section [mysqld] of MySQL configuration file. This option will allow you to start mysql and create a database dump. For example, in /etc/my.cnf:
/etc/my.cnf
---8<---
[mysqld]
innodb_force_recovery = 4
--->8---
NOTE: You may increase the option from 1 to 2, 3 to 6, until you receive a proper dump. Please see details here.
3) Start the mysqld service:
# /etc/init.d/mysqld start
4) Make a dump of all the databases, e.g.:
導出所有資料庫的資料到dump.sql
# mysqldump -uadmin -p`cat /etc/psa/.psa.shadow` -A > dump.sql
cat /etc/psa/.psa.shadow
是找出admin的密碼
If dumping failed with an error (for example "Incorrect information in file: './psa/APSApplicationItems.frm' when using LOCK TABLES"), try increasing innodb_force_recovery and try to dump the databases anew.
5) Now recreate the main database "mysql" and the InnoDB engine. To do so, stop mysqld:
~# /etc/init.d/mysqld stop
6) Remove the contents of /var/lib/mysql/. (Make sure you have all actual dumps or a recent copy of the directory backed up in section 1):
~# rm -rf /var/lib/mysql/*
7) Remove the option innodb_force_recovery in /etc/my.cnf.
8) Start mysqld:
~# /etc/init.d/mysqld start
This will recreate a main MySQL database "mysql" and InnoDB engine database. You may see that database files have been created in /var/lib/mysql/. However, note that only a default MySQL configuration was recreated. All custom databases should be restored from the dump.
9) Restore the databases from the dump:
~# mysql -uadmin -p`cat /etc/psa/.psa.shadow` < dump.sql
|
|