How to Repair MySQL Crashed MyISAM Tables

This article assumes a RedHat-based MySQL install like CentOS or earlier versions of Fedora. Modifiy default installation paths and service command syntax as required. Crashed MySQL tables can be something of a nightmare. You won’t be able to run any database queries and you’ll get back the dreaded

Table './xxx/xxx' is marked as crashed and should be repaired

First, you might want to check the table with: –

CHECK TABLE table_name;

If you’re lucky, you’ll get back an okay:-

| Table                   | Op    | Msg_type | Msg_text |
| database.table_name     | check | status   | OK       |
1 row in set (0.01 sec)

However, if there is a crash, you’ll need to attempt to repair it with: –

REPAIR TABLE table_name;

In most cases, this will work without any parameters. Sometimes the index file (.MYI) will be missing or too corrupted to repair. In that case, you can use the table definition file to repair it as follows:-


If this doesn’t work…and assuming that the database index file exists in the file-system…you’ll have to repair it with an external utility. “exit” out of the MySQL client and stop the MySQL server service with: –

service mysqld stop

Once the server has been shut down gracefully, run: –

myisamchk /var/lib/mysql/mydatabase/mytable.MYI

This assumes MySQL is installed in the default location on your file-system. If you’ve changed the data_dir variable in your “/etc/my.cnf”, point your command parameter there. Obviously, the mydatabase and mytables names are examples :-)

This utility will check the index file for errors. You can also pass several switches to this command: –

myisamchk --fast	        Perform a quick check, only verifying if the table handler closed successfully.
myisamchk --medium-check	Perform a faster check, by calculating a checksum for the indexes in each record and verifying that checksum against the index tree.
myisamchk --extend-check	Perform a thorough check of the table, verifying the data in each record.

If it finds errors, you can repair the index file with: –

myisamchk --recover /var/lib/mysql/mydatabase/mytable.MYI

This make take a while, depending on the extent of the corruption. Once this is done, you can restart the database server: –

service mysqld start

…and all should be well. However, in the most serious cases, your database table may be hosed. Make sure you always have backups, mysqldump at least :-)

, ,


  • mansi says:

    You can repair crashed MyISAM table using PHPMyAdmin also. To repair, first log in to your PHPMyAdmin account-> select your database-> select the affected table-> click on Repair Table. If this method fails to repair crashed table then you can try third party Stellar Phoenix MySQL Database recovery tool.
    Total Comment by mansi: 1

  • jollypaul22 says:

    Repair corrupted MyISAM table with myisamchk command of MySQL database: Run Myisamchk command-line and checks for errors and repairs the MyISAM database format. If not able to repair MyISAM table of MySQL database with the help of myisamchk command then try Third Party tool called “Kernel for MySQL database repair”. This utility automatically repairing a corrupt MySQL database
    Total Comment by jollypaul22: 1

Comments are closed.