What the message looks like
ERROR 1194 (HY000): Table 'wp_options' is marked as crashed and should be repaired
ERROR 145 (HY000): Table './shop/orders' is marked as crashed and should be repairedCommon causes
- The server was killed or crashed during a write: OOM killer, power loss, forced stop.
- The disk ran full while the table was written.
- The table uses MyISAM or Aria, which have no crash recovery like InnoDB.
- Table files were copied while the server was running.
- Failing disk or file system errors.
Check
- Which engine does the table use? (replace db and table)
mysql -e "SELECT table_name, engine FROM information_schema.tables WHERE table_schema = 'shop' AND table_name = 'orders'" - Check the table (read lock while it runs)
mysqlcheck --check shop orders - Is there free space on the data disk?
df -h /var/lib/mysql - Why did the server stop? Crash or kill in the log
Fix
- Make a copy first. If the table can still be read,
mysqldump shop orders > orders.sql. Otherwise copy the table files while the server is stopped. - Repair:
mysqlcheck --repair shop ordersor in SQLREPAIR TABLE shop.orders;. A repair can drop rows that are damaged, so compare the row count with your backup. - If it does not work, stop the server and run
myisamchk(MyISAM) oraria_chk(Aria) on the files. Make a copy of the files before that. - Restore from a backup if the repair loses too much.
- Fix the cause (memory, disk, power) and consider converting to InnoDB:
ALTER TABLE shop.orders ENGINE=InnoDB;. Test it first, as it changes locking and table size.
Typical scenario
After a power cut on a small server WordPress reports "Table './wp/wp_options' is marked as crashed and should be repaired". The installation dates from a time when MyISAM was still the default, and MyISAM has no crash recovery. Before you run REPAIR TABLE, copy the table files or make a dump if the table is still readable, and check the engine in information_schema.
FAQ
Why do only some tables crash?
Only MyISAM and Aria tables are open for writing in a way that can break at a crash. InnoDB uses a log to recover.
Will REPAIR TABLE lose data?
It tries to keep everything, but it can discard unreadable rows. That is why a copy comes first.
How do I see which engine my tables use?
With SELECT table_name, engine FROM information_schema.tables WHERE table_schema='wp';. If it says MyISAM or Aria, the tables are prone to this error. InnoDB practically does not show it because it recovers itself after a crash through its log.
Should I switch to InnoDB?
In most cases yes. With ALTER TABLE table ENGINE=InnoDB; you convert a table; afterwards it is crash-safe and supports transactions. Test it on a copy first and plan enough free space, because the table is rewritten in the process.
Can the server repair damaged tables by itself?
Partly. With myisam_recover_options (for Aria aria_recover_options) the server checks and repairs MyISAM tables automatically when opening them. That lengthens startup after a crash and is no substitute for a backup. Regular backups and a UPS remain the most reliable protection.