Migrate mysql database between servers

Dec 28, 2025

First of all, make sure you have mysql command available. If not install the mysql client package using the command

sudo apt install mysql-client

After the mysql command is available, then we will make a database dump from old server, transfer the dump to new server and then import the dump to the new server.

Create database dump from old server

mysqldump -h {host_address} -P {port_number} -u {user_name} -p {database_name} > {dump_name}.sql

This command might take a long time to finish based on the size of your database. Wait for it to complete. Else, the dump file will be corrupted and unusable. After the process is complete, it will create a file on the current directory when the command was executed.

Transfer the dump file

Copy the dump file to the new server. You can use scp, sftp or any other mechanisms to transfer the files.

Import the database to new server

mysql -h {host_address} -P {port_number} -u {user} -p {database_name} < {dump_name}


Create a free website with Framer, the website builder loved by startups, designers and agencies.