How to import a database via SSH
In this manual, we will teach you how to import a database (MySQL) to your Cloud server via SSH, for example, a Cloud SWPanel Smart Web D5. This is useful if the import via phpMyAdmin fails or any other issue occurs when uploading the database.
1. Environment Preparation
If you have a Cloud with an SWPanel administration panel, it is recommended to previously create a database (or delete the one you plan to import into); it must have the same name as the database to be imported. You can follow the following manual to create a database from SWPanel:
Manuel : 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 an SWPanel administration panel, you can skip this step. Subsequently, you will need to create the database manually.
2. Upload database (.sql) to the server
You must have a file '.sql', which is the database to be imported itself. When uploading this file to the server, you can do so via FTP or SFTP('root'):
Via FTP
- FTP users are limited.
- In terms of absolute path, transferred files are located in '/var/www/...'.
- You can follow the following manual to create and manage FTP users and access the server via FTP: Manuel : How to create an FTP account.
Via SFTP ('root')
- You must have access to the administrator('root') credentials.
- You can transfer files to any location on the server (global access).
- You can follow the following manual to be able to access via SFTP: Manuel : How to transfer files in any directory of your Cloud server using an SFTP client
The most important thing is to know the directory where you uploaded the database (.sql) within the server in order to import it later.
3. SSH Connection
When the server is activated, both from the web and from SWPanel, an email will be sent to your email account with the SSH access credentials (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 consult the following manual to connect to the server via SSH: Manuel : Connect to your Cloud via console using PuTTY
You can consult the following manual to connect to the server via Console from SWPanel: Manuel : How do I access my Cloud using the console via SWPanel
4. Database Import
Inside the server, you must ensure that you have the database already created in MySQL:
We access MySQL
mysql -u root -p

danger The 'password' requested corresponds to the administrator('root') password.
After accessing, you can list the current databases with the following command
show databases;

In the displayed list, you will have to confirm if you have the database; in case it does not exist, you must 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 (file .sql) and you can perform the import of the file '.sql' with the following command:
mysql -u root -p BBDDSWMANUALES < BBDDSWMANUALES_BACKUP.sql

danger The 'password' requested corresponds to the administrator('root') password.
Done! Now you have all the required information to import your MySQL database via SSH.