Číst česky →

Import MySQL database using SSH

2 min read Hukot net WebHosting MySQL

Contents Method #1 Method #2

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 user@host

In the sftp session, upload the file with put database.sql and close the session with exit.

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 #

This method can be used on webhosting!

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 (for example db80 or maria118) - 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 #

This method CANNOT be used on webhosting! It can be used on VPS.

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 (for example db80 or maria118) - 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.