Errors like Table './wordpress/wp_options' is marked as crashed and should be repaired or MySQL refusing to start after a power loss are scary, but usually recoverable. The right fix depends on the storage engine: MyISAM tables can be repaired directly, while InnoDB tables are crash-safe by design and need a different approach when something does go wrong.
First: check the engine and back up
SELECT table_name, engine FROM information_schema.tables
WHERE table_schema = 'wordpress';
Before any repair, copy what you have: a mysqldump if the server runs, or a copy of the data directory with MySQL stopped (sudo cp -a /var/lib/mysql /root/mysql-copy). Repairs can lose rows. See mysqldump backup and restore.
Check tables
CHECK TABLE wp_options;
Or check every table from the shell:
sudo mysqlcheck --all-databases --check
sudo mysqlcheck wordpress --check
Repair MyISAM tables
MyISAM (and ARIA, ARCHIVE, CSV) tables support REPAIR:
REPAIR TABLE wp_options;
REPAIR TABLE wp_options EXTENDED; -- slower, more thorough
Or for a whole database:
sudo mysqlcheck --repair wordpress
sudo mysqlcheck --repair --all-databases
If the server can’t open the table at all, use myisamchk on the files with MySQL stopped:
sudo systemctl stop mysql
sudo myisamchk --recover /var/lib/mysql/wordpress/wp_options.MYI
# harder cases: --safe-recover
sudo systemctl start mysql
On MariaDB, mariadb-check is the same tool as mysqlcheck, and Aria tables use aria_chk.
InnoDB: REPAIR doesn’t apply
REPAIR TABLE on an InnoDB table returns “The storage engine for the table doesn’t support repair”. InnoDB uses its redo log to recover automatically after crashes, so in most cases simply restarting MySQL fixes things. Real InnoDB corruption (from failing disks, full disks during writes, or bugs) is rare. When it happens:
1. Read the error log:
sudo journalctl -u mysql -n 100
sudo tail -100 /var/log/mysql/error.log
2. Start in forced recovery mode, beginning at 1 and increasing only as needed:
# /etc/mysql/mysql.conf.d/zz-recovery.cnf
[mysqld]
innodb_force_recovery = 1
sudo systemctl start mysql
| Level | Effect |
|---|---|
| 1 | Run even if corrupt pages are detected |
| 2 | Don’t run background threads (purge) |
| 3 | Don’t roll back transactions after recovery |
| 4–6 | Increasingly aggressive; data loss possible; read-only use only |
Values of 4 and above can permanently damage data files. Use them only to dump data out.
3. Dump everything you can:
sudo mysqldump --all-databases --routines --events > /root/rescue.sql
If one table fails, dump the others individually, and try that table with SELECT … INTO OUTFILE in chunks (by primary key ranges) to save what’s readable.
4. Rebuild: stop MySQL, move the old data directory aside, initialize a fresh one (or reinstall), remove the innodb_force_recovery setting, and import the dump. Then compare row counts with your expectations.
5. Or restore from backup: often faster and cleaner, combined with binary logs to reach the moment before the failure. See MySQL point-in-time recovery.
Convert MyISAM to InnoDB
MyISAM tables are not crash-safe: an unclean shutdown can corrupt them. If your crashed tables were MyISAM (common on old WordPress installs), convert them to InnoDB after repairing. See converting MyISAM to InnoDB.
Common causes and prevention
| Cause | Prevention |
|---|---|
| Disk full during writes | Monitor disk space; alert at 80%. See the df command |
| Out-of-memory kill of mysqld | Right-size buffers; add swap. See Linux swap usage |
| Power loss or hard reset (MyISAM) | Use InnoDB; clean shutdowns |
| Failing disk | Check dmesg and SMART data on dedicated servers |
| Copying data files while MySQL runs | Use mysqldump or XtraBackup. See XtraBackup |
And above all: regular, tested backups. See database backup automation.
Quick reference
| Task | Command |
|---|---|
| Check a table | CHECK TABLE t; |
| Check everything | mysqlcheck --all-databases --check |
| Repair MyISAM | REPAIR TABLE t; / mysqlcheck --repair db |
| Offline MyISAM repair | myisamchk --recover file.MYI (MySQL stopped) |
| InnoDB problems | Restart → error log → innodb_force_recovery 1–3 → dump → rebuild |
Related: MySQL error 2002 (socket) and MySQL performance tuning.