Skip to content

Dumping Your MySQL data (schema and data) from a Remote Server to Another

Posted on:Jan 27, 2024

Migrating a Database to a Remote Instance Using scp

Recently, I needed to migrate our database from a local setup—where both the database and the API server were hosted on the same EC2 instance—to a dedicated remote database server separation of concerns.

As part of this migration, I exported our database and securely copied the dump file to my local machine using scp. Here’s a breakdown of the process.


🛠️ What is scp?

scp (Secure Copy Protocol) is a command-line utility that uses SSH to copy files between machines securely. It’s great for transferring backups or configuration files between servers or your local environment.


Step 1: Prepare Your SSH Key

Make sure you have access to the private key that allows SSH access to your server. In my case, I used a key called dev_backend_key.pem.


Step 2: Run the scp Command

Here’s the command I used to copy the database dump (dump.sql) from the remote EC2 instance to my local development folder:

scp -i dev_backend_key.pem \
  ubuntu@ec2-46-271-019-759.eu-north-1.compute.amazonaws.com:/var/www/dump.sql \
  /Users/your_name/backend_server/dump.sql

Let’s break that down:

You should see output like:

dump.sql                                         100% 673KB  1.5MB/s   00:00

🎯 Tip: Export Schema Only vs. Full Data

Depending on your migration needs, you can choose to:

This gives you flexibility in how you spin up your new environment.