Extract and Import Database to Remote Server

This guide will demonstrate how to extract and import database to remote server. 


This guide allows any user with SSH access to import a database backup to a remote server and assign to a user.

Guide to Extract and Import Database to Remote Server

To extract and import database backup from server containing the backup to a remote server, follow these steps:

  1. Login to the server containing the database backup (in this example, we will use database_wp.sql.gz).
  2. Navigate to the directory containing the backup file. If the file is located at /backups/username/dbs/database_wp.sql.gz then you would enter the /backups/username/dbs directory:
    cd /backups/username/dbs
  3. Now, run the following command to unzip the database and transfer the .sql file to the destination server:
    gunzip -c database_wp.sql.gz | ssh username@server.domain.tld mysql --user=database_wp --password=db_password database_wp

Note: the destination server would need to have the correct user and password already existing.

You can use the following commands to create the user on the destination server:

CREATE USER 'database_wp'@'localhost' IDENTIFIED BY 'db_password';

GRANT ALL PRIVILEGES ON * . * TO 'database_wp'@'localhost';


CREATE DATABASE database_wp;


That's it. You've now exported the database.

  • gunzip, database, ssh, ssh commands
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

View Server PHP Environment with phpinfo.php

The phpinfo() function outputs a huge amount of information about the system you're using, such...

How to Change Root Password Using SSH

This article explains the method of changing the root password on a Linux Server using SSH....

How to Create Sudo User on CentOS

This article provides step-by-step setup guide for adding Sudo user to CentOS system. The sudo...

How to Use Sudo

This article provides a guide to using a Sudo user on CentOS server. From the command line,...

Set Server Time Zones with Timedatectl

This article provides a guide to setting the server time and server time zone settings using...