Export, import and move a MySQL database with phpMyAdmin
PrintIn short: phpMyAdmin in cPanel lets you save a MySQL database to a file (export) and load a file into a database (import), right in your browser, with nothing to install. Moving a database to another server is exactly these two jobs plus one more: pointing the site's configuration at the new database.
Finding phpMyAdmin
- Log in to cPanel. You can also reach it from the client area: open My Services and pick your hosting plan.
- Under Databases, click phpMyAdmin. It opens in a new tab.
- The left column lists the account's databases. Each name starts with your cPanel username and an underscore, for example
user_shop.
Before you move a database
- Freeze changes. Orders, comments or sign-ups made after the export will not reach the new server. For a shop or a busy site, turn on maintenance mode or choose a quiet hour.
- Keep the original. Do not delete the database on the old server until the site has run without problems on the new one for a few days.
- Moving the whole site? Files, e-mail and DNS have their own steps, covered in moving your website to TopHost. This article covers only the database.
Step 1. Export the database
With phpMyAdmin
- Click the database name in the left column to see its tables.
- Open the Export tab at the top.
- Pick a method:
- Quick dumps the whole database with standard options. This is fine most of the time.
- Custom lets you tick individual tables, choose a character set or compress the output.
- Keep SQL as the Format if the file will go back into MySQL later.
- Click Export (called Go in some versions). Your browser downloads a
.sqlfile.
Tip: for a large database, choose Custom and set compression to gzipped or zipped. The file shrinks several times over, which makes both the download and a later upload faster.
From the command line
If you have SSH access on the old server, this command asks for the password and writes a compressed copy straight away:
mysqldump -u old_user -p old_database | gzip > database.sql.gz
Whichever way you export, open the start of the file in a text editor to make sure it contains CREATE TABLE and INSERT lines and is not an error page.
Step 2. Prepare the target database
You import into a database that already exists in the account. If you do not have one yet, open MySQL Databases in cPanel, create the database and a user, then give that user ALL PRIVILEGES on it. The detailed steps are in creating a MySQL database in cPanel. Write down the database name, user name and password exactly as cPanel shows them, account prefix included.
The database should be empty. If you are importing over one that already has tables, export it first as a safety copy.
Step 3. Import the file
With phpMyAdmin
- Select the target database on the left.
- Open the Import tab.
- Click Choose File (or Browse) and pick the file from your computer. Plain
.sqlfiles work, and so do.sql.gzand.sql.ziparchives. - Leave the format on SQL and the other options as they are unless you have a reason to change them.
- Scroll to the bottom and click Import. Wait for the green success message before closing the tab.
When the file is too big for the browser
phpMyAdmin displays the maximum upload size next to the file field. If your dump is larger, try these in order:
- Compress the file and try again: a
.sql.gzarchive is several times smaller. - Import over SSH or from Terminal in cPanel (see connecting to the server via SSH). Upload the file to your account first, then run:
gunzip < database.sql.gz | mysql -u cpuser_dbuser -p cpuser_dbname
- Ask support. Upload the file with File Manager or FTP and open a ticket stating the file path and the database it belongs in.
Step 4. Update the site configuration
After a move, the site still holds the old access details in its configuration file. Replace the database name, user and password with the new ones and set the host to localhost. For WordPress this is wp-config.php:
define( 'DB_NAME', 'cpuser_dbname' ); define( 'DB_USER', 'cpuser_dbuser' ); define( 'DB_PASSWORD', 'the password you set' ); define( 'DB_HOST', 'localhost' );
Where Joomla, OpenCart, PrestaShop and other platforms keep these values is listed in MySQL connection details.
Step 5. Test before switching DNS
You can open the site on the new server before the domain points there by editing the hosts file on your computer, as described in accessing the site before the domain is delegated. Check the home page, a few inner pages, the admin login and any form. If the domain name itself changes with the move, WordPress also stores the old address in the database, and it has to be replaced there too.
Common errors and what they mean
| Error or symptom | Cause | What to do |
|---|---|---|
#1046 No database selected | No database was selected on the left before the import | Select the database, then import again from its Import tab |
#1050 Table already exists | The target database already holds tables with the same names | Export what is there as a safety copy, then empty the database or use a fresh one and import again |
#1044 Access denied on CREATE DATABASE | The file tries to create or switch to a database with a different name | Remove the CREATE DATABASE and USE lines from the file (or export again without them) and import into the selected database |
Unknown collation: 'utf8mb4_0900_ai_ci' | The dump comes from MySQL 8, and the destination uses a database server version that does not know this collation | Replace utf8mb4_0900_ai_ci with utf8mb4_unicode_ci throughout the file, using an editor that handles large files, and import again into an empty database |
Access denied; you need (at least one of) the SUPER privilege(s) | Views, triggers or procedures in the file carry a DEFINER with the old server's user | Delete the DEFINER=`...`@`...` parts from the file, or export again with the definer option turned off |
| Question marks or odd symbols instead of letters | The export and the import used different character sets | Export again with utf8mb4 and import with the same setting |
| "Error establishing a database connection" | Wrong details in the configuration file, or the user has no rights on the database | Compare names and password with cPanel, letter by letter (connection details), and check that the user was added to the database |