How to transfer database from old host to Digitalocean


I am currently having a wordpress website at cloudways and I want to migrate to digitalocean. I successfully installed wordpress using easyengine (nginx) and I transferred wp-content to the new server here.

I am stuck at migrating the database. As I can understand the default location for databases is at /var/lib/mysql . How can I transfer my old database here using an .sql or file?

Use the below command to import database from your old host to containerised MySQL dB:

cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root –password=root DATABASE

Replace your credentials, files and db name etc and you are good to go.

You may find this tutorial helpful if you wish to start from the whole migration process again.

There are many ways to handle the database migration of WP sites. My personal favorite is to use the wp-cli tools available on stock EE4 installs. But there are also various plugins that can backup, restore and migrate your site that I think are underappreciated in the ease and simplicity they provide. Then there is utilities such as phpMyAdmin (PMA) that you will find on both Cloudways and Easyengine tools.
The command line method as explained by the other poster is a valid method as well. But starting with easiest:

Plugins - To me they are all similar. I recently tried WPvivid Backup plugin and was pleasantly surprised at how easy it was to backup and migrate a site with the free version. I have used Duplicator and other in the past with success as well. The beauty of this method is that you also get a good working backup of your entire site while performing the migration and have a plugin that can continue to provide backups.

PMA - If all you need to do is copy over databases, then using PMA is a simple GUI way of managing the sql functions without all the syntax of mysql -u root -ppassword etc. It is mostly a click to export and click to import process.

WP-CLI - this is hands down my favorite as it is quick and never seems to fail me. On cloudways you would use their database tool to export a sql copy of your working database, move it to the new site just as you would your wp-content folder and then do the following on your new EE4 site:
sudo ee shell
wp db import databasename.sql

That’s it. The only catch is that you need to make sure you run the command in the same folder that the sql file resides in or make sure you point to the path where the file is stored. By using the sudo ee shell command you bypass any need to learn and use docker exec commands and all the switches. And exporting with this command is a simple wp db export and you have a database backup of your site.

Hope some of this helps you get rolling. Do this once or twice and moving/migrating sites becomes a 10 minute task between any platforms.

Thank you very much for your detailed answer.
I managed to transfer the database using duplicator.
Next time I will try wp-cli. I have tried that but without success. It seems I tried with wrong commands.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.