1. Problem log
2017-08-31 14:18:05 4122 [Note] InnoDB: Database was not shutdown normally! 2017-08-31 14:18:05 4122 [Note] InnoDB: Starting crash recovery. 2017-08-31 14:18:05 4122 [Note] InnoDB: Reading tablespace information from the .ibd files... 2017-08-31 14:18:05 4122 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace dev/tb_test uses spac e ID: 1 at filepath: ./dev/tb_test.ibd. Cannot open tablespace mysql/innodb_table_stats which uses space ID: 1 at filepath: ./mysql/ innodb_table_stats.ibd 2017-08-31 14:18:05 2ad861898590 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 ./mysql/innodb_table_stats.ibd InnoDB: We do not continue the crash recovery, because the table may becomeInnoDB: 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. 150126 14:18:06 mysqld_safe mysqld from pid file /home/mysql/mysql_app/dbdata/liuyazhuang136.pid ended
Add to the [mysqld] group:
innodb_force_recovery=6
innodb_force_recovery parameter explanation:
innodb_force_recovery affects the recovery status of the entire InnoDB storage engine. The default value is 0, which means that all recovery operations are performed when recovery is required.
When effective recovery operations cannot be performed, mysql may not be able to start and an error log will be recorded.
innodb_force_recovery can be set to 1-6, the larger number includes the impact of all previous numbers.
When the parameter value is greater than 0, select, create, and drop operations can be performed on the table, but operations such as insert, update, or delete are not allowed.
1(SRV_FORCE_IGNORE_CORRUPT): Ignore the detected corrupt page
2(SRV_FORCE_NO_BACKGROUND): Prevent the main thread from running. If the main thread needs to perform a full purge operation, it will cause a crash
3(SRV_FORCE_NO_TRX_UNDO): Do not execute Transaction rollback operation.
4(SRV_FORCE_NO_IBUF_MERGE): Do not perform the merge operation of insert buffer.
5(SRV_FORCE_NO_UNDO_LOG_SCAN): Without checking the redo log, the InnoDB storage engine will treat uncommitted transactions as committed.
6(SRV_FORCE_NO_LOG_REDO): Do not perform rollforward operation.
$mysqldump -h 192.168.209.136 -uroot -p dev > /home/mysql/dev.sql
$mysql -h 192.168.209.136 -uroot -p mysql> drop database dev; ERROR 1051 (42S02): Unknown table 'dev.tb_test'
Physically delete the frm and ibd files corresponding to tb_test
mysql> drop database dev; Query OK, 0 rows affected (0.00 sec)
mysql> create database dev; Query OK, 1 row affected (0.03 sec)
5. Remove the parameter innodb_force_recovery
After removing the previously set parameters, restart the database
##innodb_force_recovery=6
[mysql@liuyazhuang136 dev]$ mysql -h 192.168.209.136 -uroot -pmysql dev</home/mysql/dev.sql Warning: Using a password on the command line interface can be insecure. ERROR 1050 (42S01) at line 25: Table '`dev`.`tb_test`' already exists
Prompt table Already exists. This is because after removing the innodb_force_recovery parameter, the database will be rolled back and the corresponding ibd file will be generated. Therefore, the file needs to be deleted.
Re-import after deletion
[mysql@liuyazhuang136 dev]$ mysql -h 192.168.209.136 -uroot -pmysql dev</home/mysql/dev.sql
The above is the detailed content of Solving the problem in MySQL that the table data file is damaged and the database cannot be started. For more information, please follow other related articles on the PHP Chinese website!