To repair a MariaDB database, run mysqlcheck --check first to see whether tables are healthy, then escalate to mysqlcheck --repair (or REPAIR TABLE in SQL) for MyISAM/Aria tables or innodb_force_recovery settings for InnoDB corruption. The right method depends on the storage engine, the severity of the damage, and whether the server is running. Backing up before you change anything is the first real repair step, because most repairs overwrite data in place.

This guide walks through diagnosing the problem, choosing the correct repair path for MariaDB's two main engines, and verifying that the fix actually held. The steps assume MariaDB 10.x or 11.x on Linux, which is the overwhelming majority of installs, though the SQL commands work on Windows too.

Understand what "repair" means for each MariaDB engine

MariaDB doesn't have one universal repair command. The storage engine decides what tools can help and what risks they carry.

MyISAM and Aria are the classic non-transactional MariaDB engines. Aria is MyISAM's crash-safe successor and the default for internal system tables like mysql.* in many MariaDB versions. Both support REPAIR TABLE and mysqlcheck --repair. Repairing them means rebuilding indexes and, with the right options, recovering what rows it can from a damaged data file. MyISAM data files can survive a repair that Aria's transactional log might otherwise complicate.

InnoDB is the default engine for modern MariaDB tables and handles most production workloads. It has crash recovery built in through its redo log: after an unclean shutdown, InnoDB replays the log automatically on startup. That means most "corruption" you see is either a clean shutdown after hardware damage or an InnoDB-level error that ordinary REPAIR TABLE can't fix. Run REPAIR TABLE on an InnoDB table and MariaDB typically returns "The storage engine for the table doesn't support repair." Real InnoDB repair means forcing the engine into read-only recovery mode and exporting data.

That mismatch is the single most common cause of failed repair attempts. People run the command they used on an old MyISAM blog and wonder why nothing happens.

Check first: confirm corruption and find which tables are affected

Before repairing anything, establish that damage exists and which tables it touches. Guessing leads to unnecessary repairs, and each repair writes to your data.

Start by checking the error log:

Look for lines like InnoDB: Database page corruption on disk or a failed read, Table 'db.table' is marked as crashed and should be repaired, or mysqld got signal 11. The table name in the log is your target list.

From a shell, check every database with mysqlcheck in read-only mode:

The --check option doesn't modify data. Output shows each table and either OK or a status like Error, warning, or crashed. To check one database:

Inside SQL, you can also ask the server directly:

For a fast structural check across a database:

EXTENDED is slower but catches more subtle index inconsistencies. If CHECK TABLE returns OK, your problem may be application-level, a query error, or a permissions issue rather than physical corruption. Stop here and investigate the error message itself; repair won't fix a bad query.

Per-table status for an InnoDB table that's throwing errors at query time:

A non-zero Check_time alongside OK suggests it was checked before. If you see engine mismatches or suspicious row counts, note them so you can compare after repair.

Prepare before you repair: stop writes and take a backup

Repairs modify files. If you don't have a backup, the first priority is creating one before any repair attempt, even the "safe-looking" ones.

1: Put the database into a quiescent state. Ideally stop the application writing to the affected database. For a single table, avoid concurrent inserts. 2: Take a logical or physical backup. If the server still starts, dump: mysqldump --single-transaction --quick my_database > my_database_backup.sql For InnoDB, --single-transaction produces a consistent snapshot without locking the whole database. (mysqldump is the MariaDB-compatible dump tool; mariadb-dump is its modern alias in recent MariaDB versions, and both behave the same.) 3: If the server won't start or dump fails on the broken table, copy the raw data directory: sudo cp -a /var/lib/mysql/my_database /path/to/backup/ For a single InnoDB table, copy its .ibd file plus the data dictionary files. Keep the whole directory if you can—InnoDB's dictionary is shared, and mismatched copies are hard to recover. 4: Record the server version and engine. Include the output of: SELECT VERSION(); and SELECT table_name, engine FROM information_schema.tables WHERE table_schema='my_database'; This matters for reproducing any repair later.

If you have no backups and the data is critical, a filesystem-level copy of /var/lib/mysql before touching anything is your cheapest insurance.

Repair MyISAM and Aria tables

These are the engines where REPAIR TABLE and mysqlcheck --repair actually apply.

Option A: SQL repair. Start the server (even in a degraded state), connect, and run:

For a more aggressive recovery:

Two clauses matter. EXTENDED attempts to rebuild indexes from scratch. USE_FRM reconstructs the table from its .frm definition file, which can recover from a corrupted data file—but only if the .frm itself is intact, so copy the .frm alongside the backup first. USE_FRM may delete rows it can't fit into the reconstructed structure, so treat it as last resort and check row counts after.

Option B: command line. With the server stopped, mysqlcheck can repair:

Or one database:

--repair maps to REPAIR TABLE under the hood. Add --extended for the equivalent of EXTENDED, --optimize if you also want to defragment, and --use-frm only when you're deliberately rebuilding from the definition file. Because mysqlcheck --repair runs sequentially, it stops at the first hard error unless you add --force. Without --force, capture the exact table and error.

Option C: offline recovery of a single MyISAM table. Sometimes the server won't start because the mysql.* system tables themselves are MyISAM and damaged. In that case:

1: Stop mariadb. 2: Back up the affected .MYD, .MYI, and .frm files. 3: Use myisamchk on the offline files: myisamchk -r /var/lib/mysql/my_database/my_table.MYI Add -e for extended repair, or -o for "old" recovery when the table file was recreated after corruption. myisamchk modifies files, so run it only with the server stopped and after backups. 4: Use aria_chk with the same syntax for Aria tables.

Run myisamchk --help to confirm the version's flags; they've been stable for years but don't guess option semantics.

Check success by running CHECK TABLE my_table; and confirming OK, then comparing SELECT COUNT(*) against your backup or pre-incident baseline.

Repair InnoDB: force recovery, export, rebuild

InnoDB tables rarely need "repair" in the MyISAM sense. If MariaDB says a table is corrupted, the usual choices are:

Recover from a backup. Start the server with innodb_force_recovery, export, then recreate the database cleanly.

innodb_force_recovery runs from 1 to 6, increasing in severity. MariaDB's documentation describes each level:

1: stop purge operations; keep the server running for basic inspection and dumps. 2: prevent backgorund operations from running (background master thread, purge and merge). 3: skip rollback of transactions after a crash. 4: skip secondary index creation and use a default insert buffer, which avoids errors when purging InnoDB tables. 5: treat uncommitted transactions as committed (mostly for binlog-related recovery). 6: do not redo logged operations, which can create serious inconsistency in the page structure.

Set the level in /etc/mysql/mariadb.conf.d/50-server.cnf under [mysqld]:

Start MariaDB, then export affected databases:

If dump fails at level 1, raise to 2, then 3, one step at a time. Levels 4–6 are increasingly risky and can produce logically inconsistent data; they're for extracting what you can from a table that otherwise can't be read. Never leave innodb_force_recovery set for normal operation—MariaDB refuses writes at any level above 0, which breaks production traffic and often misleads admins into thinking the server is "half-working."

Once exported:

1: Stop MariaDB and comment out or remove the force-recovery line. 2: Move the old data directory aside entirely (rename /var/lib/mysql to /var/lib/mysql.corrupt). 3: Initialize a fresh data directory (mariadb-install-db or your distribution's package reinstall steps). 4: Import recovered.sql.

Check table integrity before and after import; if the imported tables still fail CHECK TABLE, the corruption persisted through the dump, which means the original export lost rows the engine couldn't read. Compare row counts to your last backup to estimate the loss.

Verify the repair held and prevent a repeat

A repair that hasn't been tested is not done. After any path above:

Run CHECK TABLE my_table EXTENDED; and confirm OK. Run SELECT COUNT(*) and a few representative queries. For a transaction table, spot-check that recent rows are present. Check the error log for new warnings after a normal restart. Restart MariaDB once, cleanly, and confirm it comes up without recovery messages. If the error log shows InnoDB replaying logs or reporting corruption again, the underlying filesystem or disk is likely the cause—repair won't hold.

Prevention usually beats the repair attempt:

Convert MyISAM tables to InnoDB if application compatibility allows: ALTER TABLE my_table ENGINE=InnoDB;. You gain crash-safe recovery and lose nothing critical on modern MariaDB. Watch disk space. MariaDB under disk pressure causes write failures that masquerade as corruption. Add innodb_buffer_pool_size sanity to your config for memory-heavy workloads and use sane innodb_file_per_table settings. Schedule mysqlcheck --check as a read-only health monitor, not --repair, for routine operation.

When to stop and get a professional

Some signs mean you're past safe DIY repair:

mysqld crashes on startup immediately, even with innodb_force_recovery=1. Multiple InnoDB tables fail, which points to a damaged filesystem or failing disk, not a MariaDB bug. Check dmesg for I/O errors and consider filesystem checks—after backing up. Dumps produced in force-recovery mode fail to import cleanly. The data is financial, customer-facing, or otherwise high-value and you don't have a verified backup.

At that point, stop writing to the volume. Every attempted repair with a failing disk risks overwriting recoverable pages.

A worked sequence for a typical mid-sized problem

Suppose a MariaDB server reports Table 'shop.orders' is marked as crashed in the error log and the application throws errors on that table. You can confirm by checking: if orders is InnoDB (most likely), REPAIR TABLE won't help. Instead, back up the database or the raw data directory, then run mysqldump --single-transaction per database. If that succeeds, stop MariaDB, initialize a clean server with the same version, import, and run CHECK TABLE orders EXTENDED. If the dump fails, restart with innodb_force_recovery=1, dump again, then raise the level only as needed. After import, compare the row count with your backup and record the difference in your incident notes. If the table is MyISAM, REPAIR TABLE orders EXTENDED is the first attempt, with USE_FRM only after a backup of the .frm file.

Both paths end the same way: a successful check and a clean restart, not just an OK line.

Questions that come up after the first repair

Can I repair an InnoDB table without dumping and recreating? Not reliably. REPAIR TABLE on InnoDB typically returns "The storage engine for the table doesn't support repair," and forcing it through innodb_force_recovery is the supported route for extracting data, not for in-place mending. Treat the recreate as part of the repair.

Does mysqlcheck --repair work on InnoDB? It runs REPAIR TABLE behind the scenes and gets the same non-support response. Its main value is batch-checking MyISAM and Aria tables and finding exactly which ones are damaged.

What about mariadb-check, mariadb-dump, and aria_chk? Recent MariaDB releases ship these as the modern names for mysqlcheck, mysqldump, and myisamchk. The tools and options are the same; use whichever exists on your install (mariadb-check --help confirms it).

Does innodb_force_recovery at level 6 mean I got everything? No. Level 6 can return logically inconsistent data, so cross-check exported counts against your last known-good backup before trusting it, and treat recovered data as needing review.