Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Restore MySQL Database with phpMyAdmin: Step-by-Step

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Restoring a MySQL database from a backup is a routine but critical task. This guide walks you through restoring a database using phpMyAdmin, the popular web-based database management tool. You'll learn how to import SQL dump files, what to do if you run into errors, and how to avoid common pitfalls. Before you start, make sure you have: a backup file (usually a .sql or .sql.gz file), access to phpMyAdmin, and enough permissions to create or overwrite a database.

What You'll Need

  • A backup file of the database (typically exported as .sql or compressed .sql.gz).
  • Login credentials for phpMyAdmin (username and password).
  • Sufficient privileges to create a database and run the import (usually available to the root user or a user with ALL privileges on the target database).
  • If the backup is large (over 100 MB), you may need to adjust PHP upload limits in your server configuration.

Step-by-Step

  1. Log in to phpMyAdmin. Open your web browser, go to the phpMyAdmin URL (e.g., http://yourdomain.com/phpmyadmin), enter your MySQL username and password, and click "Go".
  2. Select or create the target database. In the left sidebar, click on the database name where you want to restore the data. If the database does not exist yet, click "New" at the top of the left panel, enter a database name, choose a collation (usually utf8_general_ci or utf8mb4_general_ci), and click "Create".
  3. Go to the Import tab. Once inside the database, click on the "Import" tab at the top of the main panel. This opens the import interface.
  4. Choose your backup file. Under "File to import", click "Choose File" and select your .sql or .sql.gz backup file from your computer. If the file is compressed, phpMyAdmin will decompress it automatically (provided the zlib extension is enabled).
  5. Adjust import settings if necessary. Leave the "Format" as "SQL" (the default). If your backup is very large, you may see options for partial import (skip a number of queries). Only use these if the import times out; otherwise, leave them at default.
  6. Click "Go" to start the import. The button is at the bottom of the page. phpMyAdmin will process the file. For large files, this may take a while—do not close the browser tab.
  7. Check the success message. After the import, you should see a green box saying "Import has been successfully finished". If you see an error, refer to the Troubleshooting section below.
  8. Verify the restored data. Click on the database name in the left sidebar, then click on each table to see if rows are present. You can also run a simple query like SELECT * FROM your_table LIMIT 10; to confirm data integrity.

Common Mistakes

  • Importing into the wrong database. Always double-check the selected database in the left sidebar before importing. Importing into an existing database will overwrite tables with the same names.
  • Forgetting to create the database first. If the backup file does not contain a CREATE DATABASE statement, you must create the database manually before importing, or the import will fail with "No database selected".
  • Upload size limits. PHP has a default upload_max_filesize (often 2M or 8M). If your backup is larger, the import will fail silently or show an error. You need to increase these limits in php.ini or use a tool like BigDump.
  • Using an incompatible SQL format. If the backup was made with a different MySQL version or with mysqldump options that include features not supported by your server, the import may fail. Stick to standard SQL dumps.
  • Not checking for errors after import. Even if the import reports success, some rows may have been skipped due to errors. Always verify row counts or run a few queries.

Tips

  • Back up the current database before restoring. If you are overwriting an existing database, export the current data first. This gives you a rollback point.
  • Use compressed backups. .sql.gz files are smaller and upload faster. phpMyAdmin handles them automatically.
  • For large databases, use the command line. If your backup is over 500 MB, the phpMyAdmin import may time out. In that case, use mysql -u username -p database_name < backup.sql from the terminal.
  • Check the SQL file for a USE statement. Many dumps include a line like USE `database_name`;. If it points to a different database, the import will go there instead of your selected one. Edit the file if needed.
  • Disable foreign key checks for large imports. If the import fails due to foreign key constraints, add SET FOREIGN_KEY_CHECKS=0; at the top of the SQL file, and SET FOREIGN_KEY_CHECKS=1; at the end.

Troubleshooting

  • Import fails with "#1044 - Access denied for user 'user'@'localhost' to database 'db'" — Your MySQL user does not have permissions to create or modify tables in that database. Ask your hosting provider to grant you ALL privileges on the target database.
  • Import fails with "#1046 - No database selected" — The SQL file does not contain a CREATE DATABASE or USE statement, and you did not select a database before importing. Create the database first and select it in the left sidebar, then retry.
  • Import times out or stops halfway — Increase the PHP execution time and upload limits in php.ini (max_execution_time, max_input_time, memory_limit, upload_max_filesize, post_max_size). Also, consider using the partial import option (set a number of queries to skip) or switch to command-line import.
  • Error: "Script timeout passed" — This is a PHP timeout. You can try to increase the timeout or split the SQL file into smaller parts. Use a tool like mysqldump's --max-allowed-packet option when creating backups to avoid oversized packets.
  • Import succeeds but some tables are empty — Check if the backup file was truncated or if the import was interrupted. Re-import the file after fixing any timeout issues. Also, verify that the table names in the backup match the ones you expect.
  • Compressed file not recognized — Ensure the file extension is .gz and that the PHP zlib extension is enabled. You can check this in phpMyAdmin's "Status" section or by creating a simple PHP script with phpinfo().

Frequently Asked Questions

Can I restore a database without overwriting the existing one?

Yes, create a new empty database and import into that one. The import will create tables inside the selected database, leaving the original untouched.

What if my backup file is too large to upload?

Increase the PHP upload limits (upload_max_filesize and post_max_size) in php.ini, or use a tool like BigDump to import the file in chunks. Alternatively, use the command line with mysql.

Does phpMyAdmin support .zip or .tar.gz backups?

phpMyAdmin can handle .gz and .zip files if the corresponding PHP extensions (zlib and zip) are enabled. .tar.gz is not supported directly; extract the .sql file first.

Will the import delete existing tables that are not in the backup?

No, the import only adds or replaces tables that are present in the SQL file. Tables that exist in the database but not in the backup will remain unchanged.

Why do I get an error about a missing table when importing?

This usually happens if the backup file references tables that do not exist in the target database. Ensure you are importing into the correct database, and that the backup is complete and not corrupted.

Can I restore a single table from a full database backup?

Yes, open the .sql file in a text editor, find the CREATE TABLE and INSERT statements for that table, copy them into a new file, and import that file into your database.