Cause analysis and solution for MYSQL data table corruption _ MySQL

Source: Internet
Author: User
Cause analysis and solution of MYSQL data table corruption 1. cause analysis of table corruption
  
The following are common causes of mysql table destruction:
  
1. data files are damaged due to a sudden power failure on the server.
  
2. force shutdown without shutting down the mysql service first.
  
3. the mysqld process is killed when writing a table.
  
4. when myisamchk is used, mysqld is also operating the table.
  
5. disk faults.
  
6. the server crashes.
  
7. mysql bug.
  
2. Symptoms of table corruption
  
Typical symptoms of a damaged table are as follows:
  
1. when selecting data from a table, you get the following error:
  
Incorrectkeyfilefortable: '...'. trytorepolicrit
  
2. the query cannot find rows in the table or return incomplete data.
  
3. Error: Table 'P' ismarkedascrashedandshouldbere1_red.
  
4. failed to open the table: Can 'topenfile: '××. myi' (errno: 145 ).
  
5,
  
3. prevent MySQL table corruption
  
You can use the following methods to prevent mysql table corruption:
  
1. regularly use myisamchk to check the MyISAM table (note that mysqld should be disabled). We recommend that you use checktable to check the table (do not disable mysqld ).
  
2. after a large number of update or delete operations, OPTIMIZETABLE is recommended to optimize the table, which reduces file fragments and the probability of table corruption.
  
3. shut down mysqld before shutting down the server (close the service normally, do not use kill-9 to kill the process ).
  
4. use the ups power to avoid sudden power failure.
  
5. use the latest stable mysql version to reduce table corruption caused by mysql Bugs.
  
6. for the InnoDB engine, you can use innodb_tablespace_monitor to check the integrity of file space management in Space files.
  
7. perform raid on the disk to reduce disk errors and improve performance.
  
8. it is best for the database server to run only mysqld and other necessary services, instead of other business services, so as to reduce the possibility of table damage caused by crashes.
  
9. Don't be afraid of accidents. backing up tables is an effective way to prevent table damage.
  
4. repair of MySQL table corruption
  
To fix the MyISAM table, follow these steps:
  
1. use reapairtable or myisamchk to fix the issue.
  
2. if the above method does not work, use backup to restore the table.
  
For details, refer to the following practices:
  
Phase 1: Check your table
  
If you have a lot of time, run myisamchk *. MYI or myisamchk-e *. MYI. Use the-s (silence) option to disable unnecessary information.
  
If the mysqld server is down, use the -- update-state option to tell myisamchk to mark the table as 'checked '.
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.