MySQL says a table is marked as crashed and must be repaired
Table 'wp_options' is marked as crashed and should be repairedShort answer
This error means a MyISAM table was flagged as damaged. Back up the table files, run CHECK TABLE, then REPAIR TABLE. If that fails, stop the server and run myisamchk. Moving the table to InnoDB removes the MyISAM weakness behind it.
Fix it fast
1Find out which cause you have
Find out which storage engine the table uses. Repair only exists for MyISAM, ARCHIVE and CSV tables.
SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'wp_options';2Match what you see, then jump to its fix
- 1
ENGINE is MyISAM and CHECK TABLE reports the table as crashed. perror 145 gives 'Table was marked as crashed and should be repaired'.A MyISAM table was left damaged and flaggedFix - 2
The REPAIR TABLE result is not status OK, or the error returns straight away.REPAIR TABLE did not end with OKFix - 3
REPAIR TABLE or myisamchk -r refuses because the .MYI file is missing or its header is corrupt.The index file header is lost and a normal repair cannot read itFix - 4
The same table crashes again after each unclean shutdown.The table is still on MyISAM, which has no crash recoveryFix
- 1
What does the error look like?
Table 'wp_options' is marked as crashed and should be repairedTable was marked as crashed and should be repairedTable is crashed and last repair failed
Cause 1 of 4
A MyISAM table was left damaged and flagged
1Check
Back up the table's .MYD and .MYI files first, because a repair can lose data. Then ask the server to check the table.
CHECK TABLE wp_options;2Fix
Run REPAIR TABLE. By default, for MyISAM this behaves like myisamchk --recover. The last row of the result should show Msg_type status and Msg_text OK.
REPAIR TABLE wp_options;3Verify
Check the table again and read it.
CHECK TABLE wp_options;
SELECT COUNT(*) FROM wp_options;Confirmed by dev.mysql.com
Cause 2 of 4
REPAIR TABLE did not end with OK
1Check
The manual says to try the slower safe recovery when a MyISAM repair does not return OK. The server must be stopped before you run myisamchk on its files, and mysqladmin shutdown returns before the server has fully stopped.
sudo systemctl stop mysql
sudo systemctl status mysql2Fix
With the server stopped and the files backed up, run myisamchk from the database directory: first the quick index repair, then the full recovery, then safe recovery.
cd /var/lib/mysql/mydb
myisamchk -r -q wp_options.MYI
myisamchk -r wp_options.MYI
myisamchk --safe-recover wp_options.MYI3Verify
Start the server and run CHECK TABLE again.
sudo systemctl start mysql
mysql -e "CHECK TABLE mydb.wp_options"Confirmed by dev.mysql.com
Cause 3 of 4
The index file header is lost and a normal repair cannot read it
1Check
The manual limits REPAIR TABLE ... USE_FRM to this case: the .MYI file is missing or its header is corrupted.
ls -l /var/lib/mysql/mydb/wp_options.*2Fix
Use USE_FRM as a last resort. It loses the current AUTO_INCREMENT value and does not reclaim space from deleted rows, and it must not be used on compressed tables.
REPAIR TABLE wp_options USE_FRM;3Verify
Check the table and set the AUTO_INCREMENT value again if the table had one.
CHECK TABLE wp_options;
SHOW CREATE TABLE wp_options;Confirmed by dev.mysql.com
Cause 4 of 4
The table is still on MyISAM, which has no crash recovery
1Check
REPAIR TABLE only supports MyISAM, ARCHIVE and CSV; it does not cover InnoDB. A table that is still MyISAM keeps the same weakness.
SELECT TABLE_NAME FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'mydb' AND ENGINE = 'MyISAM';2Fix
Rebuild the table as InnoDB. ALTER TABLE with an ENGINE clause rebuilds the table.
ALTER TABLE wp_options ENGINE = InnoDB;3Verify
The engine column now says InnoDB.
SELECT ENGINE FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'wp_options';Confirmed by dev.mysql.com
How do I stop it coming back?
- Convert MyISAM tables to InnoDB so the server can recover them after a crash.
- If the server exits during a repair, run REPAIR TABLE again straight after the restart, before anything else touches the table.
- Keep a recent dump so that a failed repair costs you one restore.
- After a repair on a replicated source, repair or rebuild the replicas too, because the manual says the repair changes are not propagated.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
A query on Aurora MySQL dies with 'table /rdsdbdata/tmp/#sql... is full'
ERROR 1114 (HY000): The table '/rdsdbdata/tmp/#sqlfd_1586_2' is full
In Aurora MySQL 3, internal temporary tables share one pool, and when that pool and the memory-mapped overflow file are used up, a reader instance ends the query with error 1114.
3 causes, each with a fixDatabases
Azure Database for MySQL refuses a connection that does not use SSL
ERROR 3159 (HY000): Connections using insecure transport are prohibited while --require_secure_transport=ON.
Azure Database for MySQL Flexible Server requires encrypted connections by default (require_secure_transport = ON, TLS 1.2).
4 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fixDatabases
DBeaver fails to resolve Maven dependencies when downloading a database driver
A driver library does not download automatically
DBeaver downloads driver jars from a Maven repository.
3 causes, each with a fixDatabases
DBeaver cannot verify the MySQL server certificate
unable to find valid certification path to requested target
DBeaver's MySQL driver is checking the server certificate and Java does not trust the CA that signed it.
2 causes, each with a fix