How do I import a .sql file via the command-line?

If you've set up SSH access for a package then you can run the following command-line instructions to import a MySQL database:

mysql -h hostname -u username -p username < databasefile.sql

The above command connects to your database with the -h (hostname) -u (username) -p (database name in this case) then the unzipped file < databasefile.sql

You will then be prompted to enter a password for the database. Input the password and press enter.

Compressed files

If the database file is zipped then you will need to unzip it first, then you can use one of the following commands:

For a .zip file you can use the unzip command:

  • unzip databasefile.sql.zip
  • mysql -h hostname -u username -p username < databasefile.sql

For a .gz file you can use the gunzip command:

  • gunzip databasefile.sql.gz
  • mysql -h hostname -u username -p username < databasefile.sql
Was this answer helpful?

Related Articles

What’s the cost of a Microsoft SQL database?

For Microsoft SQL databases, there is a 70 RM monthly charge for a 1GB database. This covers the...

Can I set my database hostname as ‘localhost’?

No, you would need to set the database hostname as the server that it's on at shezawebhost. You...

Does ‘Back Up Multiple Sites’ backup databases?

Yes. You can back up multiple sites from the Back Up Web Hosting icon under the Reseller Manager...

How do I manage my Microsoft SQL database?

We recommend using SQL Server Management Studio (SSMS) for managing your Microsoft SQL databases....

How do I create a MySQL database in Control Panel?

You can create MySQL databases in seconds directly from your Shezawebhost control panel.  This...