Skip to content
DBAExperts
MySQL Backups & recovery

How to restore a MySQL backup from a SQL dump

Restoring a dump means running the SQL file against the server. This operation can overwrite data, so first confirm where you are restoring and which database you are touching. Always work calmly and against the right database.

  1. 1

    Create the target database if it does not exist

    A single-database dump usually does not include the CREATE DATABASE statement. Create it before restoring.

    mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS mi_base CHARACTER SET utf8mb4;"
  2. 2

    Restore the SQL file

    Redirect the file into the mysql client. This operation writes data: make sure you are pointing at the right database.

    mysql -u usuario -p mi_base < mi_base_2026-07-04.sql
  3. 3

    Restore a compressed backup

    Decompress on the fly without creating an intermediate file.

    gunzip < mi_base.sql.gz | mysql -u usuario -p mi_base
  4. 4

    Verify that the data is complete

    Compare row counts or check key tables against the source. Never assume a restore succeeded without looking.

    mysql -u usuario -p mi_base -e "SHOW TABLES; SELECT COUNT(*) FROM tabla_clave;"

// common mistake

Restoring onto a database that already has data does NOT empty it first: the INSERTs can collide with existing keys or duplicate rows. If you want a clean restore, restore onto a freshly created database, never onto production blindly.

// when it's worth an expert

When a restore fails halfway through, takes hours, or you cannot tell whether it came out intact, every minute counts. At dba.mx we run recoveries with integrity checks and a bounded downtime window, at a fixed price.

Book an assessment — from USD $550

This guide is for reference and uses example commands. In production, adapt to your version and test in a safe environment first.