Fix Mysql Table Is Marked As Crashed And Should Be Repaired [Solved]

Immediate Fix

The fastest way to resolve a crashed MySQL table is by executing the REPAIR TABLE command directly within your SQL console. This works for MyISAM tables which are the most common victims of this error.

-- Log into MySQL and run:
REPAIR TABLE table_name;

Using the myisamchk Utility

If the MySQL server is unresponsive or you cannot log in, you can use the command-line utility. You must stop the MySQL service before running this tool to prevent further corruption.

# Stop the MySQL service
sudo systemctl stop mysql

# Navigate to your data directory and run repair
myisamchk -r /var/lib/mysql/your_database/table_name.MYI

# Restart the service
sudo systemctl start mysql

Technical Explanation

The “table is marked as crashed” error typically affects the MyISAM storage engine. This happens because MyISAM does not have the same crash-recovery capabilities as InnoDB.

When MySQL writes data, it sets a “dirty” flag in the table header. If the process is interrupted—such as during a “Crashes to Desktop” event—the flag is never cleared. Upon restart, MySQL sees this flag and prevents access to protect data integrity.

Common causes include sudden power loss, running out of disk space during a write operation, or a hard kill of the mysqld process. In rare cases, faulty hardware like a failing hard drive can also trigger this state.

A conceptual illustration showing the repair of a crashed MySQL database table.

Alternative Methods

If the standard repair commands do not work, you may need to use more aggressive recovery methods or graphical interfaces.

Repair via phpMyAdmin

For users on managed hosting or those who prefer a GUI, phpMyAdmin offers a one-click repair tool that executes the necessary logic in the background.

Step Action
1 Open phpMyAdmin and select your database.
2 Check the box next to the crashed table in the list.
3 In the “With selected” dropdown at the bottom, click “Repair table”.

Force Recovery Mode

If the table is InnoDB and refuses to start, you might need to use the innodb_force_recovery setting in your my.cnf or my.ini file. This allows you to dump the data even if the engine is corrupted.

[mysqld]
innodb_force_recovery = 1

Start with level 1 and increase up to 6 if necessary. Once you have exported your data, remove this line, restart MySQL, and re-import the data into a fresh table.