Whether you're moving a website to a new host, restoring an older version of your data, or copying a database between two hosting accounts, you'll usually do it through phpMyAdmin, the database management tool built into your hosting control panel. This guide covers exporting a database to a file and importing it back in, for both cPanel and DirectAdmin.
Before You Start
- You need a destination database and database user already created before you import into it. See How to Create a MySQL Database and Database User if you haven't set one up yet.
- The database user must have full privileges on the destination database, otherwise the import will fail partway through.
If you're restoring a WordPress or other CMS database, the table names in the exported file need to match what the application expects. Don't rename tables during export unless you also update the application's configuration to match.
Exporting a Database
In cPanel
- Log in to cPanel and open phpMyAdmin from the Databases section.
- In the left sidebar, click the database you want to export.
- Click the Export tab at the top.
- Leave the export method set to Quick and the format set to SQL, unless you have a specific reason to change them.
- Click Go. Your browser will download a .sql file containing the full database.
In DirectAdmin
- Log in to DirectAdmin and click phpMyAdmin under the Extra Features or Databases section.
- Select the database you want to export from the sidebar.
- Click the Export tab.
- Keep Quick selected as the export method and SQL as the format.
- Click Go to download the .sql file.
Importing a Database
In cPanel
- Open phpMyAdmin from cPanel and select the destination database from the sidebar. It should be empty before you import into it.
- Click the Import tab.
- Click Choose File and select the .sql file you exported earlier.
- Leave the format set to SQL and click Go at the bottom of the page.
- Wait for the confirmation message showing the import completed successfully.
In DirectAdmin
- Open phpMyAdmin and select the empty destination database.
- Click the Import tab.
- Click Choose File, select your .sql file, and leave the format as SQL.
- Click Go and wait for the success message.
If the Import Fails or Times Out
phpMyAdmin has an upload size and execution time limit set by the server, so very large databases can fail partway through with a timeout or a file size error. If this happens, try one of the following:
- Compress the .sql file into a .zip or .gz archive before uploading. phpMyAdmin can import compressed files directly and this reduces the upload size considerably.
- Split a very large export into smaller files using a text editor or a dedicated tool, then import each part in order.
- If neither option works, contact support with the database size so it can be imported directly on the server.
Once the import finishes, open a few tables in phpMyAdmin to confirm the data looks correct before pointing your website's configuration file at the new database.