Import a database

import, mysql, sql dump, phpmyadmin, mysql command, migration · 0 found this helpful

Importing loads a saved .sql file (a dump) into a database. You do it when moving a site from another host, or restoring your own copy.

Before you start

  • Create an empty database and user. See Create a MySQL database and user.
  • Have your .sql file, or a .sql.gz compressed copy.
  • Back up the target if it already holds data. Imports can overwrite tables.

Option 1: phpMyAdmin (small files)

  1. Open Account → Hosting → your site → Databases and click Open phpMyAdmin. See Use phpMyAdmin.
  2. Click the target database in the left list.
  3. Click Import.
  4. Choose your file. Leave Format as SQL.
  5. Click Import.

phpMyAdmin accepts files up to about 150 MB, and large imports may time out. For bigger files, use option 2.

Option 2: Command line (large files)

  1. Upload site.sql to your account with SFTP or the file manager in Files. See Connect with SFTP or FTP.
  2. Connect by SSH. See Connect with SSH.
  3. Run:
# Plain SQL file
mysql -u yourusername_shop -p yourusername_bakery < ~/site.sql

# Compressed file
gunzip < ~/site.sql.gz | mysql -u yourusername_shop -p yourusername_bakery

Enter the database password when asked.

With WP-CLI inside a WordPress folder:

wp db import ~/site.sql

After importing a WordPress database

If the domain changed, update addresses. See Change a WordPress site's URL:

wp search-replace 'https://old.example.ca' 'https://example.ca' --dry-run

If something goes wrong

Error Meaning and fix
ERROR 1044 Access denied The file contains CREATE DATABASE or USE. Remove those lines, or import into the right database
ERROR 1045 Access denied for user Wrong user or password
ERROR 1062 Duplicate entry Table already has data. Drop tables first, or import into an empty database
Unknown collation: utf8mb4_0900_ai_ci The dump came from MySQL 8. Replace it with utf8mb4_unicode_ci in the file with sed -i 's/utf8mb4_0900_ai_ci/utf8mb4_unicode_ci/g' site.sql
Got a packet bigger than 'max_allowed_packet' Re-export with smaller extended inserts, or ask support
MySQL server has gone away Large file or timeout. Use the command line
phpMyAdmin stops at 100% Import partially ran. Check tables, drop them, and retry on the command line

Was this helpful?

Still stuck? Ask us and we'll walk you through it.