Guides and tutorials

Hundreds of tutorials and step by step guides carefully written by our support team.

How to import a database via SSH

In this manual we will show you how to import a database(MySQL) into your Cloud server using SSH, for example a Cloud SWPanel Smart Web D5. This is useful if the import via phpMyAdmin fails or any other issue when uploading the database.

1. Environment preparation

If you have a Cloud with SWPanel administration panel, it is advisable to previously create a database (or delete the one you plan to import), this must have the same name as the database to import. You can follow the following manual to create a database from SWPanel:

How to create a MySQL or MariaDB database.

In this way, the imported database will be manageable from SWPanel.

info NOTE: If you do not have a Cloud with SWPanel administration panel, you can skip this step. Afterwards you will have to create the database manually.

2. Upload the database (.sql) to the server.

It is necessary that you have a .sql file which is itself the database to import, when uploading this file to the server you can do it via FTP or SFTP("root"):

Via FTP

  • FTP users are limited.
  • In terms of absolute path, the transferred files are located in "/var/www/... ".
  • You can follow the following manual to create, manage FTP users and access the server via FTP: How to create an FTP account.

Via SFTP ("root")

  • You must have access to administrator("root") credentials.
  • You can transfer files at any location on the server (global access).
  • You can follow the following manual to be able to access via SFTP: Access the Cloud server via SFTP client

The most important thing is to know the directory where you uploaded the database (.sql) inside the server to later import it.

3. SSH connection

At the time of registering the server, both from the web and from the SWPanel, you will be sent an email to your email account with the access credentials SSH (IP, port, user and password) of your Cloud server for the administrator user ("Root"). With these credentials, you will be able to access your server.

You can refer to the following manual to connect to the server via SSH: Connect to your Cloud via console using PuTTY

You can consult the following manual to connect to the server via Console from SWPanel: How do I access my Cloud using the console through SWPanel

4. Importing the database

Inside the server, you must make sure that you have the database already created in MySQL:

Access to MySQL

mysql -u root -p

enter image description here

danger The requested password, corresponds to the administrator's password ("root").

After login, you will be able to list the current databases with the following command

show databases; 

enter image description here

In the displayed list you will have to confirm if you have the database, in case it does not exist, you will have to create it following point 1 ("Environment preparation") or create it manually with the following command:

create database BBDDSWMANUALES;

Once you have the database in MySQL, you must go to the database directory (.sql file) and you can import the ".sql" file with the following command:

mysql -u root -p BBDDSWMANUALES < BBDDSWMANUALES_BACKUP.sql

enter image description here

danger The requested password, corresponds to the administrator's password("root").

That's all! you now have all the information required to import your MySQL database via SSH.