How to Resolve Error 1712: Index table_name is corrupted

  • by
Got this error when using mysqldump for backing up a database. At this moment, we can't do any operations but DDL.
mysqldump: Error 1712: Index table_name is corrupted when dumping table `table_name` at row: 0
Or met this error when queried the table.
ERROR 1712 (HY000): Index table_name is corrupted
In the log, you can also see the errors.
[root@test ~]# less /var/log/mysqld.log
...
2015-11-18 21:32:27 3185 [ERROR] Got error 180 when reading table './database_name/table_name'
2015-11-18 21:32:54 3185 [ERROR] /usr/sbin/mysqld: Sort aborted: Index table_name is corrupted
...

This error explicitly said the error came from one of the indexes, not the data. It could be easier than Error 2013 to debug. Chances are, it might recover itself at times by restarting the server. If the error continues appearing, you may consider the following solutions.

Now, allow me to conclude the solution straightly then I will explain the details later in this post.
Recreate the problematic index.
The recreation includes two actions in fact, dropping and creating index. Sometimes, it may cost you to drop some columns. But now the key questions we should ask ourselves first are:
  1. Which one is the problematic index?
  2. Why could an index be corrupted?
  3. What kind of situations can make it corrupted?
The questions are almost able to answer themselves: Constraints. Only constraints can stop indexes going further. So, we should look for the following indexes in sequence.
  1. Primary index.
  2. Unique index.
  3. Foreign index.
In my case, only the auto incremental sequence in the primary key can not be controlled by business logic. I suspect the primary key has duplicate values causing the index corrupted, so I just recreate the primary key by issuing one statement of DDL to solve the problem. You may refer the following post for the statement.
How to Reassign Sequential Numbers on the Auto Incremental Column

As you can see, I drop the auto increment column and the primary key as well, then add them back to the table. But if the column is quite critical for you, we need some other ways to solve it.

If you don't want to drop the auto increment column because it's referenced by other tables currently, you can try to exempt this column from being a part of primary key or unique index to make the table query-able. Then find out the duplicates, remove it manually, add the column back to primary column.

If all the above approaches failed, you may drop all indexes, remove the problematic rows, then add all the indexes back. This can be the last resort.

Leave a Reply

Your email address will not be published. Required fields are marked *