1. Home
  2. Cloud & Dedicated Servers
  3. MySQL
  4. How to Repair a Corrupted MySQL table

How to Repair a Corrupted MySQL table

Open a command prompt on your Windows server and enter the following:
(replace the values with your MySQL username, password, and database name)

 

mysqlcheck -u<USERNAME> -p<PASSWORD> –databases <DB-NAME>

(Note there are no spaces before the username and password)

 

This will then check your database and if you do have a corrupt table you will see some errors, such as:


DATABASENAME.wp_ngg_album OK
DATABASENAME.wp_ngg_gallery OK
DATABASENAME.wp_ngg_pictures OK
DATABASENAME.wp_options
warning : Table is marked as crashed
warning : 1 client is using or hasn’t closed the table properly
warning : Auto-increment value: 121441 is smaller than max used value: 121443
error : Checksum for key: 1 doesn’t match checksum for records
error : Corrupt
DATABASENAME.wp_postmeta OK
DATABASENAME.wp_posts OK

 

To attempt a repair, log into your database:

mysql -u<USERNAME> -p<PASSWORD>

 

Then at the MySQL prompt, enter:
(replace DB-NAME with your database  name) 

use <DB-NAME>;

and then type:

REPAIR TABLE `<TABLE-NAME>`;

 

 

For example, the above example shows that table wp_options is corrupt, so to repair this table we do:

 

mysql> REPAIR TABLE `wp_options`;
+————————-+——–+———-+———-+

| Table                   | Op     | Msg_type | Msg_text
|+————————-+——–+———-+———-+
| DATABASENAME.wp_options | repair | status   | OK      
|+————————-+——–+———-+———-+

 

 

 

Content retrieved from: https://support.appliedi.net/kb/a501/how-to-repair-a-corrupted-mysql-table.aspx.

Updated on November 11, 2019

Was this article helpful?

Related Articles

Need Support?
Can't find the answer you're looking for? Don't worry we're here to help!
CONTACT SUPPORT

Leave a Comment