Site icon Information2 | Data Management & Recovery Pioneer

How to Restore MySQL Database from SQL Dumps & Physical Files

Type of MySQL Backup Files

Before restoring, you need to know what type of backup file you have. MySQL backups fall into two categories: logical backups (SQL scripts) and physical backups (raw data files). Using the wrong restore method for your file type will cause errors — or worse, silent data corruption.

File Type Created By Best For Restore Method
.sql / .dump mysqldump, mysqlpump Migrations, small-to-medium databases MySQL command line
.sql.gz mysqldump + compression Large databases, remote transfers Decompress, then import
.ibd InnoDB engine Single-table recovery Manual file replacement
.ibdata InnoDB engine Full InnoDB system tablespace recovery Manual file replacement
.frm MySQL 5.7 and older Table structure metadata Manual file replacement
.MYD / .MYI MyISAM engine MyISAM table data and index recovery Manual file replacement

Note: Avoid copying physical files between significantly different MySQL versions (e.g., 5.7 to 8.0) without testing. Schema formats changed between major releases and can cause startup failures.

Restore MySQL Database from SQL Dump Files

SQL dump files are the most common MySQL backup format. They’re portable, human-readable, and compatible across most MySQL versions — making them the standard choice for migrations and routine restores.

Before you start: Most dump files don’t include a CREATE DATABASE statement. If the target database doesn’t exist yet, create it first:

CREATE DATABASE your_database_name;

Restore from a .sql File

Use the mysql command-line client to pipe the file directly into your target database:

mysql -u username -p database_name < backup.sql

You’ll be prompted for your password. MySQL will then execute every statement in the file and rebuild your tables and data.

Restore from a .dump File

A .dump file is structurally identical to a .sql file — just a different extension. The command is exactly the same:

mysql -u username -p database_name < backup.dump

Restore from a Compressed Backup (.sql.gz)

Large databases are often stored as .sql.gz files to save space. You don’t need to decompress the file first — pipe it directly into MySQL in one step.

Linux / macOS:

gunzip < backup.sql.gz | mysql -u username -p database_name

Windows (PowerShell):

cmd /c "gunzip -c backup.sql.gz | mysql -u username -p database_name"

Tip: Piping directly avoids writing a large temporary file to disk, which matters when storage is limited.

Common Pitfalls

Restore MySQL Database from Physical Data Files

Physical data files — sometimes called “flat files” or “cold backups” — are the raw binary files MySQL uses to store data on disk. Restoring from these files is faster than replaying a SQL dump, but it requires more care around file permissions and version compatibility.

When to Use Physical File Restoration

This method is best suited for the following scenarios:

Steps to Restore Physical MySQL Data Files

Follow these steps in order. Mistakes in file placement or ownership are the most common reasons a physical restore fails.

Step 1: Stop the MySQL Service

Never move or replace data files while MySQL is running. Doing so risks dirty writes and file corruption.

Step 2: Replace the Database Files

Copy your backup files into the MySQL data directory:

Note: If you’re restoring InnoDB tables, the ibdata1 and ib_logfile* files must come from the same backup as your .ibd files. Mismatched system files will cause tablespace ID errors and prevent MySQL from starting.

Step 3: Adjust File Permissions

On Linux, MySQL must own all files in the data directory. This is the most frequently missed step in a physical restore.

sudo chown -R mysql:mysql /var/lib/mysql

sudo chmod -R 750 /var/lib/mysql

Windows handles file permissions differently — as long as the MySQL service account has read/write access to the data folder, no additional changes are needed.

Step 4: Restart MySQL

Start the service and watch for errors.

Tip: Check the MySQL error log immediately after restarting — look for hostname.err on Windows or run sudo journalctl -u mysql on Linux. Any tablespace mismatch or permission issue will show up here before it causes bigger problems.

Verify the Restored MySQL Database

A restore isn’t complete until you’ve confirmed the data is intact. Skipping verification can lead to silent failures — the database appears to be running, but the application crashes when it hits a missing table or corrupted row.

Step 1: Check the Database Structure

Confirm that all expected tables were recreated. Log into the MySQL shell and run:

USE your_database_name;

SHOW TABLES;

Compare the output against your original schema or documentation. Any missing tables likely indicate an interrupted import.

Step 2: Verify Table Row Counts

Tables can exist but be empty if the restore was cut short. Check the row counts for your most critical tables:

SELECT COUNT(*) FROM users;

SELECT COUNT(*) FROM orders;

Tip: If you recorded row counts at the time the backup was taken, compare them now. A lower number usually points to an incomplete import or a max_allowed_packet error during the restore.

Step 3: Spot-Check Data Integrity

Run a few queries on recently updated records to confirm the data is readable:

SELECT * FROM orders ORDER BY created_at DESC LIMIT 5;

Pay attention to any garbled text, which can indicate a character encoding mismatch — a common issue when moving files between different operating systems or MySQL versions.

Step 4: Test Application Connectivity

Restart your application or web server and perform a basic operation — logging in, loading a dashboard, or running a report. This confirms the application can reach the database and query it successfully.

Note: If the connection fails, check your MySQL user permissions — specifically the HOST value. A user defined as 'user'@'localhost' won’t work for remote connections; use 'user'@'%' if the application connects from a different host.

Simplify MySQL Backup & Recovery with i2Backup

Manual restore procedures work — but they depend on having a clean, complete backup file ready when you need it. In practice, ad hoc backups are easy to forget, hard to verify, and often incomplete by the time a real recovery is needed. A dedicated backup solution removes that uncertainty by automating the entire process from scheduling to recovery.

i2Backup is an enterprise backup platform that lets you back up and restore MySQL databases through a visual web console, with support for physical servers, virtual machines, and cloud environments — all managed from one place.

Key Feature of i2Backup

The steps in this guide give you full control over manual MySQL restores. But a reliable recovery starts long before a failure happens — with consistent, verified backups. i2Backup automates that foundation, so when you do need to restore, the process is straightforward rather than a scramble.

FREE Trial for 60-Day

FAQ

Q1: How do I recover a MySQL database from data files on Windows?

Stop the MySQL service via services.msc. Copy your .ibd, ibdata1, and .frm files into C:\ProgramData\MySQL\MySQL Server X.X\Data. Make sure the MySQL service account has full read/write permissions on the new files, then restart the service.

 

Q2: How do I restore MySQL from binary logs?

Use the mysqlbinlog utility to convert the log file into SQL statements and pipe them into MySQL:

mysqlbinlog binlog.000001 | mysql -u username -p

Binary log recovery is used on top of a full backup — always restore your base backup first, then replay the binlogs to recover changes up to the point of failure.

 

Q3: How do I restore a MySQL database using files from the data folder?

Shut down MySQL, then move the database folder into the data directory. Make sure ibdata1 comes from the same backup as your table files. On Linux, reset file ownership with chown -R mysql:mysql before restarting.

 

Q4: Can I restore a single table from a .sql dump file?

Restore the full dump into a temporary staging database, then export just the table you need:

mysqldump -u username -p staging_db table_name > single_table.sql

mysql -u username -p target_db < single_table.sql

 

Q5: What should I do if I get a “Table already exists” error?

Drop and recreate the target database before importing:

DROP DATABASE your_database_name;

CREATE DATABASE your_database_name;

Conclusion

Restoring a MySQL database comes down to knowing your backup type. SQL dump files are straightforward to import with the mysql command line. Physical data files are faster for large datasets but require careful attention to file permissions and tablespace consistency. Either way, always verify the restore before pointing your application back at the database.

The best time to test your recovery process is before you actually need it. Consider a dedicated solution like i2Backup to automate your MySQL backups and ensure you always have a clean, verified restore point ready.

Exit mobile version