HOW DO I IMPORT A .SQL FILE VIA THE COMMAND-LINE?

Created by Salim Shadman, Modified on Mon, 28 Aug, 2023 at 6:08 AM by Salim Shadman

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 article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article