Home > Database > Mysql Tutorial > body text

Detailed explanation of MySQL table data file corruption causing the database to fail to start

黄舟
Release: 2017-10-01 07:43:24
Original
4543 people have browsed it

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
Copy after login

2. Solution

1. Add the following parameters to my.cnf

Add to the [mysqld] group:

innodb_force_recovery=6
Copy after login

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.

2.Back up the database

$mysqldump -h 192.168.209.136 -uroot -p dev > /home/mysql/dev.sql
Copy after login

3.Delete the database

$mysql -h 192.168.209.136 -uroot -p
mysql> drop database dev;
ERROR 1051 (42S02): Unknown table 'dev.tb_test'
Copy after login

Physically delete the frm and ibd files corresponding to tb_test

mysql> drop database dev;
Query OK, 0 rows affected (0.00 sec)
Copy after login

4.Create Database

mysql> create database dev;
Query OK, 1 row affected (0.03 sec)
Copy after login

5. Remove the parameter innodb_force_recovery
After removing the previously set parameters, restart the database

##innodb_force_recovery=6
Copy after login

6. Import data

[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 &#39;`dev`.`tb_test`&#39; already exists
Copy after login

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
Copy after login

The above is the detailed content of Detailed explanation of MySQL table data file corruption causing the database to fail to start. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!