Restore MySQL database backup


When to restore a backup?

Restoring a backup is necessary when:

  • ✅ You accidentally lost data
  • ✅ The database is corrupted
  • ✅ You need to go back to a previous version
  • ✅ You're migrating to another server

Method 1: Restore from phpMyAdmin

Step 1: Access phpMyAdmin

  • Log in to phpMyAdmin
  • Select the database where you want to restore
  • If the database doesn't exist, create it first

Step 2: Open Import tab

  • Click on the Import tab

Step 3: Select backup file

  • Click Choose File
  • Select the SQL backup file from your computer
  • The file can be .sql, .sql.gz, or .zip

Step 4: Configure options

  • Leave default options generally
  • If the file is large, phpMyAdmin will process it in parts
  • Click Go or Continue

Step 5: Wait for restoration

  • Wait for the process to complete
  • You'll see a confirmation message when it finishes

Method 2: Restore from terminal

Restore uncompressed SQL file:

mysql -u user -p database_name < backup.sql

Example:

mysql -u root -p my_webapp < backup_2024.sql

It will ask for the password and restore the backup.

Restore compressed file (.gz):

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

Or in one step:

zcat backup.sql.gz | mysql -u user -p database_name

Restore all databases

If the backup contains all databases:

mysql -u root -p < all_databases_backup.sql

⚠️ Warning: This will restore all databases. Make sure the backup is correct.


Restore to a new database

If you want to restore to a new database:

Step 1: Create the database

mysql -u root -p -e "CREATE DATABASE new_database;"

Step 2: Restore the backup

mysql -u root -p new_database < backup.sql

Verify restoration

After restoring, verify that everything is correct:

mysql -u root -p database_name -e "SHOW TABLES;"

Or from phpMyAdmin, verify that tables are present and have data.


Common issues

"Access denied" error

  • Verify that the user has sufficient permissions
  • Verify that the password is correct
  • Use root user if necessary

"Unknown database" error

  • The database doesn't exist
  • Create the database first before restoring

SQL syntax error

  • The file may be corrupted
  • Verify that the file is valid SQL
  • Try restoring from phpMyAdmin which can handle errors better

File is too large

  • For very large files, use terminal
  • Increase PHP limits if using phpMyAdmin
  • Or split the file into smaller parts

Restore only specific tables

If the backup contains multiple tables and you only want to restore some:

Option 1: Extract tables from backup

# Extract only lines from a specific table
grep -A 10000 "CREATE TABLE.*table_name" backup.sql > extracted_table.sql
mysql -u root -p database_name < extracted_table.sql

Option 2: Restore everything and then delete what you don't need

  • Restore the complete backup
  • Delete tables you don't need from phpMyAdmin or MySQL

Important tips

  • ⚠️ Backup before restoring: Make a backup of current database before restoring
  • Verify backup: Make sure the backup file is correct
  • Empty database: It's better to restore to an empty or new database
  • Timing: Do restoration during low traffic hours
  • Verification: Verify that restoration was successful after completing

Need help?

If you're having trouble restoring a backup or need assistance, open a ticket from the billing.baires.host panel or contact us for support.

You can also reach us through our social media:

Was this answer helpful? 0 Users Found This Useful (0 Votes)