To get a MySQL database back after a system failure, first confirm whether the server software and data directory survived, then start MySQL and repair or restore from backups as needed. The decisive condition is what remains on disk and what backups exist: a clean shutdown with an intact data directory often means a simple restart or InnoDB crash recovery, while corrupted files or lost storage require restoring a dump or physical backup. Work from the least destructive check upward, and stop before writing anything to failing storage. The order below moves from inspection to recovery to verification, with the trade-offs that shape each choice.
Before You Touch Anything: Protect the Evidence
Recovery outcomes are decided in the first few minutes, mostly by what you don't do. Treat the failed machine as a crime scene until you know what's recoverable.
First, stop the server from being written to. If MySQL crashed hard—power loss, kernel panic, container kill—InnoDB will run crash recovery the next time it starts, and that process writes to the data files. Starting the server prematurely on damaged storage can turn a recoverable tablespace into a lost one. If disks are making clicking or grinding noises, power the system down and get an image made before any software work.
Second, capture the state. Note the MySQL version (mysqld --version), the operating system, whether the server is a standalone instance, part of replication, or in a cluster, and where datadir and the error log live. If the server is running but misbehaving, pull the last few hundred lines of the error log and the output of SHOW ENGINE INNODB STATUS before changing anything.
Third, make a copy. If you have another disk with space, copy the entire data directory—including the ibdata* files, mysql/, and each database folder—plus the binary logs and the configuration file (my.cnf or my.ini). On Linux, cp -a or rsync -a preserves ownership and permissions; on Windows, use a file-level copy while MySQL is stopped, or use a volume shadow copy. This copy is your fallback if a repair attempt makes things worse.
Fourth, keep the original untouched while you work on the copy. Point a scratch MySQL installation at the copied datadir, not the original, for any experiment.
The success check here is simple: you have a byte-for-byte copy of the data directory and logs, and you know the MySQL version. Fail to do that, and every later step carries more risk.
Step by Step: Getting the Server Running Again
The following procedure assumes a single MySQL server (or a MariaDB-compatible fork) that was running before the failure, and that you have access to the machine and its disks. Adapt paths to your platform; on Debian/Ubuntu systems the datadir is typically /var/lib/mysql, and configuration lives under /etc/mysql.
Prerequisites: confirmation that the storage is physically healthy (SMART status, RAID controller status, no I/O errors in dmesg), a copy of the data directory as described above, and the MySQL version.
1: Check whether mysqld is already running partially. Run ps aux | grep mysqld on Linux or check the Services panel on Windows. A half-dead process can hold file locks and cause confusing errors. If it exists, try a clean mysqladmin shutdown first; force-kill only if it's unresponsive, then wait a few seconds before restarting.
2: Inspect the error log before restarting. On Linux, look at /var/log/mysql/error.log or the log_error path from the config; on Windows, check the *.err file in the data directory. The last lines usually say exactly what the previous failure was: a killed process, a full disk, a corrupt page, or a permissions problem.
3: Verify free disk space. A full disk is one of the most common causes of "MySQL is down" after a reboot. df -h on Linux or a drive check on Windows. If the disk is full, free space before starting; otherwise InnoDB may fail to initialize and the server will exit again.
4: Check ownership and permissions. MySQL must own its data directory. On Linux, ls -ld /var/lib/mysql should show mysql:mysql (or whatever user the server uses for the running installation), and files should be readable and writable by that user. A restored-from-backup directory often has the wrong owner, which produces "Can't create/write to file" or "Unable to lock ./ibdata1" errors.
5: Start the server and watch the log. Run systemctl start mysql (or service mysql start, or mysqld_safe &), then tail the error log. A normal InnoDB startup ends with something like "InnoDB initialization has ended" or "ready for connections." Crash recovery messages ("Starting crash recovery", "Rolling back trx", "Applying redo to page") are expected after a hard kill and mean InnoDB is doing its job—don't interrupt it.
6: Connect and check the version. Run mysql -u root -p -e "SELECT VERSION(); SHOW DATABASES;". The version should match the one the data directory came from. If it doesn't, that matters (see the incompatibility section below).
7: Run a basic integrity check. CHECK TABLE on MyISAM tables and SHOW ENGINE INNODB STATUS for InnoDB are quick sanity checks. For InnoDB, the "Transactions" section should have no long-running "RECOVERING" state.
8: If InnoDB reports corruption, don't panic. The first move is to see whether the server can start at all in read-only mode (--innodb-force-recovery=1 or =2 in my.cnf, or via mysqld --innodb-force-recovery=1). With force recovery 1 or 2 the server may start even with some corrupt pages. At that point, dump every database you can reach and restore into a fresh datadir. The force-recovery levels above 2 are diagnostic only and are not a long-term operating mode.
If the server starts and the tables are readable, the "recovery" is effectively done. If it starts but some databases are missing, or tables throw "table is marked as crashed", you're now in backup-restore territory (next section).
Stop conditions: if the storage is failing (I/O errors in the log, SMART warnings), if the log shows filesystem or hardware-level corruption, or if the MySQL version makes --innodb-force-recovery unusable for your needs, get a storage or database professional involved. Do not keep restarting a server whose error log shows hardware failures.
Reading the Error Log: What It Tells You
The error log is the single most useful piece of evidence, and most people skip it.
Look for these signals:
"InnoDB: Database page corruption on disk" or "InnoDB: page ... checksum mismatch" — real corruption; recovery will need a dump-and-restore. "InnoDB: Unable to lock ./ibdata1" — either another mysqld is running or permissions/ownership are wrong. This is a startup blocker, not data loss. "InnoDB: Ignoring the redo log due to the larger than 4GB file size" or messages about the redo log being unusable — a torn or partially written redo log, which can happen with storage that lost power. The InnoDB recovery process can usually rebuild from the tablespace, but this is where a backup becomes important. "InnoDB: Operating system error number 28 in a file operation" — that's ENOSPC (code 28 on Linux): disk full. Free space and retry. "Error: Table '...' is marked as crashed and should be repaired" — a MyISAM table (or a crashed InnoDB table in older versions) needs REPAIR TABLE (MyISAM) or mysqlcheck. "Cannot open datafile for read-only" or "Unknown storage engine" after a version upgrade — the datadir belongs to a different version.
If the log is blank or truncated, check its log_error path in my.cnf and start the server in the foreground: mysqld --user=mysql --console on Windows, or mysqld --user=mysql in a terminal on Linux, so messages print to your screen.
The Two Main Recovery Routes: Repair In Place vs. Restore
Once you know the system is behaving and the data directory is intact enough to start, you have two honest options. They're not really alternatives to choose at random; the question is which one is safe for your data.
In-place recovery keeps the existing data files and lets InnoDB's crash recovery, CHECK TABLE, REPAIR TABLE (MyISAM), or --innodb-force-recovery bring them back to a usable state. It's fast and needs no backup, but it's the right choice only when the corruption is minor and you're working on a copy. On a primary online system it's risky: repair operations can drop rows, and force recovery can leave an inconsistent server.
Restore from backup takes a known-good snapshot—a mysqldump SQL file, a mysqlpump output, a xtrabackup/mariabackup physical backup, or a binary snapshot—and loads it into a fresh MySQL instance. It's slower and loses whatever happened after the backup, but it's the trustworthy route when the original files are suspect. Every realistic recovery plan should treat this as the fallback and test it before you need it.
A simple rule: if the error log shows actual page corruption, restore. If the server starts into force-recovery mode and you can dump the data, do that—a logical dump is a fine way to migrate out of a damaged datadir into a fresh one. The dump then becomes your "backup," and restoring it is a controlled operation.
Restoring from SQL Dumps and Physical Backups
The mechanics differ by backup type, and getting the details right matters.
Logical dumps (mysqldump). On a fresh server, create the databases first if your dump doesn't include CREATE DATABASE statements (a --databases or --all-databases dump does; a single-database dump typically doesn't unless you use --databases). Load with mysql -u root -p < mydump.sql or mysql -u root -p dbname < mydump.sql. For large dumps, run with --max_allowed_packet=1G if needed, and consider --single-transaction on the dump side—it's what lets a dump be taken without locking tables on InnoDB. Verify by comparing row counts or checksums on a few key tables against the source.
Physical backups (Percona XtraBackup, MariaDB Backup, or a binary snapshot). These require the datadir to be copied into place and the server started against it, with the same caveats as any datadir move: permissions, ownership, and matching version. XtraBackup's --prepare step must be run before the backup is usable. If your backup used --stream or incremental files, the restore process involves applying those layers; follow the tool's documented procedure rather than improvising.
Binary logs. If binary logging was enabled (log_bin in my.cnf), the binlogs let you replay changes made after the last full backup. mysqlbinlog converts them into SQL you can pipe back into the server. This is how you close the gap between the backup and the crash—but binlogs are only useful if they exist and weren't on the lost storage, which is a reason to keep them on a different volume.
Replication. If the failed server was a replica, the safest path is often to rebuild it from its source: take a fresh backup from the primary, restore it to the replica, and point the replica at the source. If the primary itself failed and a replica is healthy, promote the replica—that's a role change, not a restore, and it's the fastest way to restore availability on a well-designed replication setup.
The success check for every restore is the same: connect, run CHECK TABLE on key tables, compare a few data points with the source of truth, and confirm the application can write a test row.
Common Failure Modes and Their Fixes
The most frequent post-crash problems are surprisingly mundane.
"Can't connect to local MySQL server" — the server isn't running; check systemctl status mysql or the Windows service state, then the error log. "Access denied for user 'root'@'localhost'" — the data directory may have come from a different root password. If you still have the old datadir, this is resolvable; if it's lost, use --skip-grant-tables to reset credentials on a copy, then restore the proper authentication setup. Never do this on a production server without a plan. "InnoDB: Unable to lock ./ibdata1" — another process holds it. Find and stop the second mysqld; on Windows check for a mysqld.exe left over, and verify that your test instance isn't pointed at the production datadir. "Table 'x' is marked as crashed" — for MyISAM, REPAIR TABLE x; from the mysql client, or mysqlcheck --auto-repair. For InnoDB, don't repair—dump and restore. Server starts but all databases are missing — the server is using the wrong datadir. Check datadir in my.cnf; a fresh installation points somewhere else (on Debian/Ubuntu, the packaged install may default to /var/lib/mysql, and a restore may put files elsewhere). "Incorrect key file for table" — usually a MyISAM index issue after a crash; REPAIR TABLE with USE_FRM is the documented fallback if the regular repair fails. The disk filled up again immediately — the crash was likely caused by a full disk in the first place. Find and clear the old binlogs (PURGE BINARY LOGS), the error log if it's rotated poorly, or an oversized tmp directory before restarting.
Each of these has a reversible check first: confirm what's actually running, what the log says, and what the config points at. Only after those come the riskier repairs.
After the Database Is Back: Making Recovery Repeatable
The crash is a diagnosis, not just an incident. The steps above recover a database; the steps below make sure the next crash costs less.
Verify the backup chain. A backup you haven't restored isn't a backup. Restore the most recent dump into a scratch instance and run integrity checks—row counts, a few known tables, and the application's smoke tests. If your backups are physical, test the restore procedure end to end; XtraBackup and MariaDB Backup have documented verify commands, but a restore into a separate server is the real test.
Check the recovery window. Determine how much data would be lost in a repeat scenario: the interval between the last full backup and the crash. If binary logs are enabled, the window is smaller because you can replay them. Confirm that binlogs, dumps, and physical backups all land on separate storage from the primary datadir—if the same disk failure takes both, none of it helps.
Look at the cause. A crash from disk full, a kernel OOM kill, a container memory limit, or a failed cloud volume is diagnosable in the system logs (dmesg, /var/log/syslog, cloud provider event logs). Fixing the cause—adding disk monitoring, increasing memory, setting container resource limits more carefully, moving logs off the data volume—reduces the chance of a repeat.
Document the procedure. The steps you just ran are your runbook. Write down the datadir path, the config path, the version, the backup location, and the exact restore commands. Test it once on a staging machine so the real recovery is mechanical rather than improvised.
A Note on Version Mismatches and Forks
A datadir belongs to a specific MySQL version and family. Starting a data directory written by MySQL 8.0 on a MySQL 5.7 binary, or the reverse, usually fails or corrupts data. MariaDB is a fork that uses a compatible-ish on-disk format in some versions, but "mostly compatible" is not a recovery strategy. If you don't know which version wrote the datadir, check the error log for the version string or the mysql_upgrade history. Install the matching major version (ideally the matching minor) for recovery, and plan an upgrade after the data is back and backed up.
This matters most after an OS reinstall, where a package manager may install a newer major version than the backup came from. Restore into a matching-version server first, dump, and then upgrade—rather than starting an old datadir on a new server and hoping.
What You Can't Recover Without Evidence
Some outcomes are out of reach, and it's better to know that early than to spend hours on a dead end.
If the storage failed and there is no backup, the data may be gone. Software can't recreate what the disk no longer holds. A data-recovery lab can sometimes read failing platters, but that's a professional service with no guarantee, and the cost and turnaround are real. If the system had no backups and the storage is suspect, get the drive to a recovery specialist before writing anything else to it.
If the only copy of a dump was on the same volume as the datadir, a disk failure takes the backup too. Check for copies on other machines, snapshots at the cloud or hypervisor level, or an offsite backup service you set up and forgot about. It's worth the ten minutes of searching before concluding.
If the server was a replica and its source is gone with no backups, the replica's data is the last copy—treat it carefully, make a physical copy, and don't experiment on it.
The honest summary is that a database can be recovered from a crash when the data files are intact enough to start or when a backup exists in a location the failure didn't reach. When neither holds, the answer is data recovery service or accepting loss. Keeping the copy of the datadir and the logs makes the first two cases much more likely to end well.