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:
- Login to the server containing the database backup (in this example, we will use database_wp.sql.gz).
- 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:
- 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 firstname.lastname@example.org 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'; FLUSH PRIVILEGES; CREATE DATABASE database_wp;
That's it. You've now exported the database.