


Detailed explanation of MySQL table data file corruption causing the database to fail to start
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
2. Solution
1. Add the following parameters to my.cnf
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.
2.Back up the database
$mysqldump -h 192.168.209.136 -uroot -p dev > /home/mysql/dev.sql
3.Delete the database
$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)
4.Create Database
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
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 '`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 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.
