# Import MySQL database using SSH

Source: https://www.hukot.net/community/en/tutorials/importing-mysql-database-using-ssh
Updated: 2026-11-26

*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.](https://www.hukot.net/community/en/tutorials/howto-set-up-ssh-with-public-key-authentication-on-debian-ubuntu)  
Importing the database can be done using two methods.

### <u>Method #1</u>

> [!NOTE]
> 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](https://admin.hukot.net/) 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.

### <u>Method #2</u>

> [!NOTE]
> 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](https://admin.hukot.net/) in database overview.  
If the file is located other than in the root directory, we must specify the relative path to the file.
