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

Manish Garg

Last Update 2 jaar geleden

"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

See our guide on how to connect to your package via SSH.

You might also like to read:

Hot to create a MySQL database

How to I import a .sql file via phpMyAdmin?

Reseller Hosting with cPanel: Pros and Cons

Powerful and easy Managed Cloud Hosting"

Was this article helpful?

0 out of 0 liked this article

Still need help? Message Us