Moving a database to another account or server

Export the database from the source, create an empty database and user at the destination, import the file and point the application at the new connection details. What always changes is the database and user name, because cPanel prefixes them with the account name. So the application’s configuration file has to be edited.

Step by step

1 Stop the writes. If the site takes orders, comments or sign-ups, put it in maintenance mode for the final copy. Anything that arrives after you export stays behind.
2 Export the database. See exporting with phpMyAdmin. If it is large, use mysqldump.
3 At the destination, create the database and the user and link them. See creating the user and the privileges.
4 Import the file into the empty database. See importing with phpMyAdmin.
5 Edit the configuration of the application: database name, user, password. In WordPress they are DB_NAME, DB_USER and DB_PASSWORD in wp-config.php. The host stays localhost.
6 Test before you change the DNS, using the hosts file. See testing before you change the DNS.
7 Do not delete the source until the destination has been working for a few days.

What changes from one account to the other

Item What happens
Database and user name They change, because of the account prefix. Update them in the application.
Server (host) Stays localhost when the application and the database are on the same server.
Collations and engine If the copy comes from MySQL 8, adjust the collations. See MySQL or MariaDB.
Addresses stored inside the database Some programs store the site address in the database itself. In WordPress, changing domain takes more steps. See moving WordPress to a new domain.
Routines and views with DEFINER May fail on import. Remove the DEFINER=... part from the file.
The costliest mistake is the data gap. You export at 10:00, switch the DNS at 14:00, and the orders from those hours stayed in the old database. Do the final export inside the maintenance window and only then change where the domain points.

After the move

Over the following days, confirm that new orders and sign-ups show up at the destination and that the PHP error log is empty. Watch the DNS: some visitors keep reaching the source for a while because of caching. If the source keeps working, they write there and the data is lost. So leave the source in maintenance mode (not just idle in the database) until you are sure. Only then delete it, and keep the final export, which is the last faithful copy of what was there.

Moving the whole site, not just the database? Files, e-mail and databases travel better in a single move. See internal migration between plans and moving a site by hand.

Changing servers and want help planning the window without losing data? Tell us what you have and we will agree the route.

Open a support ticket

SEE ALSO

Moving a site by hand: files by FTP and the database

How to migrate a site without downtime

Hosting migration

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $6.59/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?