


Solving the problem in MySQL that the table data file is damaged and the database cannot be started
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 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!

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

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.

The steps to build a MySQL database include: 1. Create a database and table, 2. Insert data, and 3. Conduct queries. First, use the CREATEDATABASE and CREATETABLE statements to create the database and table, then use the INSERTINTO statement to insert the data, and finally use the SELECT statement to query the data.

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.