You can recover a MySQL database from a Mac's data by locating the raw data directory (usually /usr/local/var/mysql on Intel Homebrew installs or /opt/homebrew/var/mysql on Apple Silicon), stopping the server cleanly, and copying the schema folders out before anything else touches them. If MySQL still starts and the tables are readable, a mysqldump export is the safer route. The hard case—corrupted InnoDB files or a dead server—needs file-level recovery from a cloned copy of the disk, not from the live folder. The order matters more than the tool: preserve first, test second, restore third.

This guide covers the three realistic situations Mac users hit: a working server with damaged or deleted tables, a MySQL install that won't start, and a Mac that won't boot at all with the database trapped inside. Each has a different starting point, and mixing them up is how people overwrite the exact file they needed.

Identify which recovery case you're in before touching anything

Recovery goes wrong when people start reinstalling MySQL or running repair commands before they know what's actually broken. Spend five minutes classifying the failure first.

Case A: MySQL runs and accepts connections. You can log in with the mysql client, SHOW DATABASES returns your schemas, but data is missing, a table is corrupted, or someone ran a bad DELETE or DROP. This is the easiest case.

Case B: MySQL won't start, but the data directory exists. The launchd service fails, mysql.server start errors out, or the process dies during startup. The files are probably still on disk. InnoDB may need crash recovery, the socket or PID file may be stale, or permissions may be wrong.

Case C: The Mac won't boot, or the disk was erased. The database lives on the internal drive or an external volume, and you need to pull files off before reinstalling macOS. This requires booting from another volume or mounting the drive elsewhere.

A quick check that sorts A from B: open Terminal and run mysqladmin -u root -p status. If it returns uptime and thread counts, you're in Case A. If it returns "Can't connect to local MySQL server through socket," you're in Case B or C.

One more distinction matters throughout: MyISAM tables (older installs, .MYD/.MYI/.frm files) and InnoDB tables (the default since MySQL 5.5, with .ibd files and the shared ibdata1 tablespace) fail and recover differently. InnoDB corruption is generally more recoverable through the server itself because of the redo log and crash recovery; MyISAM tables are more forgiving to copy file-by-file because each table is self-contained, but they're also more prone to silent corruption after a hard shutdown.

Prerequisites: clone the data before you experiment

The single most important rule: never run repair or recovery commands against your only copy.

If the Mac boots normally, copy the entire MySQL data directory to an external drive before doing anything else. You need enough free space equal to the size of the data directory plus room for the export. On macOS you'll also need:

Terminal access and an admin account (some paths require sudo). The MySQL root password, or a user with ALL PRIVILEGES, for any server-side export. The exact MySQL version, if possible—run mysql --version. Restoring into a different major version usually works but can fail on newer features; matching the version removes a variable. For Case C, a second Mac or an external enclosure so you can mount the drive without booting from it.

To find the data directory when the server runs, run mysql -u root -p -e "SELECT @@datadir;". Note it exactly; Homebrew puts it under /usr/local/var/mysql (Intel) or /opt/homebrew/var/mysql (Apple Silicon), the official Oracle DMG installer uses /usr/local/mysql/data, and MAMP uses /Applications/MAMP/db/mysql[version]. XAMPP uses /Applications/XAMPP/xamppfiles/var/mysql. If you're not sure which install you have, which mysql and ps aux | grep mysqld narrow it down.

Copying a live data directory while the server is running can capture a torn, inconsistent snapshot. For Cases A and B, stop MySQL first if you can. For Case B where it won't stop cleanly, copy anyway—an inconsistent copy is still better than none—but treat it as read-only evidence, not something to start the server on.

Case A: Export a working database with mysqldump

When the server runs and the data is readable, mysqldump produces a logical backup—SQL statements that recreate the schema and rows. It's the most portable recovery because it doesn't depend on file formats, page sizes, or operating system.

Step 1 — Confirm the server and list databases. Run mysql -u root -p -e "SHOW DATABASES;". Identify the schema you need and note its name.

Step 2 — Check the tables are actually readable. Run mysql -u root -p yourdb -e "CHECK TABLE tablename;" for suspicious tables, or mysqlcheck -u root -p --all-databases for a sweep. A table that returns "OK" is exportable. One that returns "corrupt" may still export partially—attempt it, but expect gaps.

Step 3 — Export the schema and data. The basic command is mysqldump -u root -p --single-transaction --routines --triggers yourdb > ~/Desktop/yourdb_backup.sql. The --single-transaction flag gives a consistent snapshot for InnoDB tables without locking them. Add --events if you use scheduled events, and --databases yourdb if you want the CREATE DATABASE statement included in the dump. For all schemas at once, use --all-databases.

Step 4 — Verify the dump before trusting it. Check the file size is plausible (ls -lh) and inspect the tail: tail -n 5 ~/Desktop/yourdb_backup.sql. A complete dump ends with a line like -- Dump completed on .... If that line is missing, the export was interrupted—rerun it. Grep for CREATE TABLE count and compare it to SHOW TABLES output.

Step 5 — Restore into a clean instance. Create a fresh database (CREATE DATABASE yourdb_restored;), then run mysql -u root -p yourdb_restored < ~/Desktop/yourdb_backup.sql. Success check: SELECT COUNT(*) FROM a few known tables, and confirm row counts match what you expected. If the original was corrupted, expect some rows to be missing and compare against application-level records.

If a single table is corrupted but the rest are fine, dump the healthy tables and attempt the damaged one separately with --ignore-table exclusions. Sometimes SELECT * FROM damaged_table still returns most rows even when CHECK TABLE complains, and you can export that result set with a SELECT ... INTO OUTFILE or by piping through the client.

Case B: Start MySQL long enough to export

When the server won't start, the goal is to get it running just long enough to export, then deal with the files. Resist the urge to reinstall—Homebrew's brew reinstall mysql and Oracle's installer both leave the data directory alone in most cases, but a careless uninstall can remove it.

Step 1 — Read the error log. This is the highest-value step. On Homebrew installs, the error log is typically in the data directory as hostname.err; check ls -lt /opt/homebrew/var/mysql/.err (or the Intel path). Oracle installer logs live in /usr/local/mysql/data/.err. MAMP logs are under /Applications/MAMP/logs/mysql_error.log.

The log usually names the cause directly: "Another mysqld process is already running," "Can't create/write to file" (permissions), "InnoDB: Database page corruption," or "unknown variable" (config file problem). Each points to a different fix.

Step 2 — Clear stale processes and socket files (reversible). Run ps aux | grep mysqld and kill any leftover process with sudo kill -9 PID. Then remove stale mysql.sock and hostname.pid files from the data directory only if no server is running. Restart with brew services start mysql or sudo mysql.server start. If it comes up, jump to Case A immediately and export.

Step 3 — Address permissions. A common Mac failure after migration or restore is ownership drift. Run sudo chown -R _mysql:_mysql /opt/homebrew/var/mysql (Homebrew runs MySQL as _mysql; adjust the path to yours). Then retry the start. If the log says a file is unreadable, check ls -l on the specific file the log names.

Step 4 — Force InnoDB crash recovery if corruption is reported. In /etc/my.cnf or /opt/homebrew/etc/my.cnf, add under [mysqld] the line innodb_force_recovery = 1. Start the server. Values 1 through 6 escalate; 1 skips less, 6 is most aggressive and makes tables read-only. Start at 1, and if the server won't start, try 2, then 3. Once it starts, immediately dump everything with mysqldump—the server is in a degraded state and you should not write to it.

A critical cautions: at innodb_force_recovery of 4 or higher, InnoDB refuses writes, and you must remove the setting and let the server complete normal recovery before using the restored copy in production. Never leave the setting in place.

Step 5 — Export, then rebuild. With the server running under recovery mode, dump all databases. Then stop the server, remove the innodb_force_recovery line, and restore the dump into a fresh data directory. This is effectively a clean rebuild and is the most reliable outcome from corruption.

If the server refuses to start at any recovery level, the data directory needs file-level recovery (Case C approach), not server-side tricks.

Case C: Recover files from a Mac that won't boot

When macOS itself is the problem, the database is just files on a volume. The recovery is about reading those files without letting the original system modify them.

Step 1 — Stop writing to the drive. If the Mac is on and the disk is failing, power it off. Don't run First Aid, don't reinstall macOS, don't let the machine boot normally—each operation can write to the volume and potentially overwrite deleted or damaged data.

Step 2 — Mount the drive from another system. The cleanest options are Target Disk Mode (Intel Macs, hold T at boot) or a USB-C/Thunderbolt external enclosure for the removed drive. Apple Silicon Macs don't support Target Disk Mode in the same way; use another Mac with a working system or an enclosure. For APFS volumes with FileVault, you'll need the recovery key or the login password to decrypt.

Step 3 — Copy the data directory before extracting anything. Once mounted, navigate to the MySQL data path (/opt/homebrew/var/mysql, /usr/local/mysql/data, or the MAMP/XAMPP equivalent) and copy the whole folder to your working Mac's desktop with cp -R or Finder. This is your working copy; leave the original volume untouched.

Step 4 — Bring the copy up on a matching MySQL install. Install the same MySQL major version on the working Mac, stop it, and point its datadir at the copy (or copy the schema folders into a fresh data directory). Then start it and attempt an export. If it starts, treat it exactly like Case A. If it doesn't, work through Case B's error-log and recovery-mode steps against the copy.

Step 5 — Use file-level tools only when the server can't read the files. InnoDB's per-table .ibd files can sometimes be recovered with tools that read the InnoDB page structure directly, but results depend on page size and whether the file is internally consistent. This is the last resort, not the first, because it produces partial data that needs validation. If the copy starts under innodb_force_recovery, that path is usually better than external tools.

One scheduling detail: recovering files from a dead Mac often takes hours, and the MySQL copy should be made in the first session, before any attempt to reinstall the OS on the original machine.

What separately stored InnoDB files change about recovery

Since MySQL 5.6, InnoDB stores each table in its own .ibd file inside the database folder by default (innodb_file_per_table=ON), with the shared system tablespace in ibdata1. This is generally good for recovery: if ibdata1 is damaged but the per-table .ibd files are intact, a fresh data directory with the same schema can sometimes absorb the table files.

To use this, create a fresh data directory with the same MySQL version, create the database and tables with matching definitions (or restore a schema-only dump), stop the server, copy the .ibd files over the fresh ones, and start again with innodb_import_table_from_5_6 or the modern ALTER TABLE ... IMPORT TABLESPACE procedure. This works when the table's internal space IDs match the target server's tablespace—which they do when the target is a fresh install and you import in the correct order.

The catch: if the original server ran with innodb_file_per_table=OFF, everything is inside ibdata1, and you can't split individual tables out. In that case your options narrow to server-level recovery or table-copying tools. Check the setting in the original my.cnf or by querying SHOW VARIABLES LIKE 'innodb_file_per_table'; on any surviving instance.

For most users, the practical takeaway is simpler: keep innodb_file_per_table=ON because it makes future recovery easier, and when you copy a data directory for recovery, copy all of it—.ibd, ibdata1, and the redo logs (ib_logfile0, ib_logfile1)—in one operation.

Verify the restore before deleting anything

Recovery isn't finished when the server starts. It's finished when you've confirmed the data is right and have a second copy.

Check row counts against a known baseline. If the application reports 14,382 orders and the restored table shows 14,382, you're aligned. If it shows 14,377, five rows were lost to corruption—find out which and whether they matter.

Run consistency checks on the restored instance. mysqlcheck -u root -p --all-databases --check should return "OK" for every table. SELECT COUNT(*) and a few spot SELECT queries against critical tables confirm content, not just structure.

Test with your actual application before pointing production at it. Point a staging copy of the app at the restored database and exercise the read paths it uses. This catches missing indexes, triggers, or routines that a row-count check misses.

Keep two copies, in two places. One local copy and one on an external drive or a different machine. The original data directory on the Mac, even if it's the source of truth, should not be your only copy during this process.

A realistic sequencing example: a MacBook with a Homebrew MySQL 8.0 install fails to boot after a botched macOS upgrade. You remove the SSD, mount it in an enclosure on a colleague's Mac, and copy /opt/homebrew/var/mysql (about 3.2 GB) to an external drive—20 minutes. On your working machine, you install MySQL 8.0 via Homebrew, stop it, replace its data directory with the copy, and start it. It might come up cleanly; if it doesn't, the error log likely shows InnoDB corruption, and innodb_force_recovery=1 gets it running. You then run mysqldump --all-databases --routines --triggers --single-transaction > all.sql (another 10–15 minutes for 3 GB). That dump restores into a fresh data directory, and the original copy stays on the external drive as a fallback.

Common failure modes and the stop conditions

Several failure modes account for most failed recoveries on Macs:

Copying the data directory while the server runs. Produces a torn snapshot. Stop the server first; if it won't stop, copy anyway but mark the copy as suspect. Starting recovery against the original data directory. Any write during recovery can destroy evidence. Always work on a copy. Reinstalling MySQL without preserving the data directory. Most installers leave it alone, but not all—and a "clean uninstall" script can delete it. Clone first. Wrong ownership after restore. The server refuses to start with permission errors. chown -R _mysql:_mysql on the data directory is the fix on Homebrew installs. Ignoring the error log. The log almost always names the cause. Read it before changing anything. Using innodb_force_recovery as a permanent setting. It's a recovery mode, not a fix. Remove it after exporting, then rebuild.

Stop conditions: if the data matters commercially or legally, stop and engage a professional data-recovery service before running any repair tool, especially if the drive itself is making noises, clicking, or failing SMART checks. If the Mac's drive is physically failing (not just unbootable), power it down and seek professional help—no software step improves the odds. And if innodb_force_recovery above level 3 is required simply to start the server, treat that copy as evidence only and restore from the export, not the recovered directory.

FAQ

Can I just copy the data directory to another Mac and use it? Sometimes. Copying the directory preserves the database, but the receiving machine needs a matching MySQL version and matching file paths for the config to work. It's usually cleaner to copy the directory, start the server, export with mysqldump, and restore the dump into a fresh install—the dump is version-portable and validates cleanly.

Does Time Machine back up the MySQL data directory? Yes, by default, if it's not in a location Time Machine excludes. That means a recent Time Machine snapshot can be the fastest recovery path—restore the data directory from a snapshot taken while MySQL was stopped, or at least before the damage occurred. Check that the snapshot predates the problem, and remember that a snapshot from a running server may have the same torn-state risk.

What if I don't know the MySQL root password? On Homebrew and Oracle installs, you can start the server with --skip-grant-tables (which disables authentication), reset the password, and restart normally. Do this only on the recovery copy, never on a server exposed to a network.

Is there a way to recover a single deleted table without a full dump? Yes, when innodb_file_per_table was on and you have the original .ibd file—the ALTER TABLE ... IMPORT TABLESPACE procedure can attach an existing tablespace to a matching table definition. It requires matching schema and is fiddly; a full dump and selective restore is usually more reliable if a dump exists.

This is general education, not individual recovery consulting. For a database that supports a business, financial records, or legal obligations, consult a qualified database administrator or professional data-recovery service before running repair tools on the only copy. If the drive may be failing, power down and seek professional hardware recovery first.