Import MySQL database using SSH
Tutorial assumes that you already have your .sql file on the server. If you haven't uploaded it yet, you can do so via sftp:
sftp server-ip@host get database.sql
Note: Host is going to be either IP address of your VPS or one of our hosting servers (vix.hukot.net or eam.hukot.net).
Now we're going to connect to our domain using SSH.
Importing the database can be done using two methods.
Method #1
We're going to connect to database using command mysql - we'll need to enter a password after pressing enter.
mysql -h host-name -u database-name -p
Note: host-name is name of server where database is stored (vix or eam) - in case of hosting being on the same server as database, we don't need to use paramater -h at all.
We can find host server in administration of hosting services in database overview.
We're going to select our database using command use.
mysql> use database-name
Using source we're going to import the database.
mysql> source database.sql
If the file is located other than in the root directory, we must specify the relative path to the file.
Method #2
Easier method using only command mysql:
mysql -p -u database-name -h host-name database-name < database.sql
Note: host-name is name of server where database is stored (vix or eam) - in case of hosting being on the same server as database, we don't need to use paramater -h at all.
We can find host server in administration of hosting services in database overview.
If the file is located other than in the root directory, we must specify the relative path to the file.