PROFESSIONAL WEB HOSTING SOLUTIONS
US 1-877-412-4678      International 1-317-961-1116

Importing/Exporting Databases from Command Line Print

  • database, import, export
  • 6

How to Import and Export databases using Command Line

 

Using command line provides a quick and easy way to import and export databases in just a few minutes. You will only need a few commands and some basic knowledge regarding your database name and username.

 

As always, it is recommended you take a local backup before making any changes to your site.

 

Importing a Database

 

     To import a database, the file must be in .sql format. You cannot upload a database that is compressed in any way, such as a .tar.gz or .zip format.

1: Upload the database to your account using either File Manager or through SSH. 

2: Create your MYSQL database you plan to put your .sql file in. Note the username and password for step 4.

3: Using SSH (either through your local machine or through the Terminal area in your cPanel), navigate to the folder you placed your .sql database in.

4: Run the following command(the username and database name are the ones you noted in step 2):

  

mysql -p -u username database_name < file.sql


If you get a blank return on your terminal, your import should be complete. 

 

   Importing a single table into an existing database using the command below:

mysql -u username -p -D database_name < tableName.sql


 

Exporting a Database

 

Using SSH from either your local machine or your cPanel Terminal, run the following command:

   

mysqldump -p -u username database_name > dbname.sql


Once you have run the command, you will be asked  to enter the database password. Once this is entered, your database should be in the folder you entered the command from, and ready for download to a local machine.

 

You can also download a single table from your database using the below command:

 

mysqldump -p --user=username database_name tableName > tableName.sql



As always, if you have any issues, dont hesitate to reach out to our support staff!


Was this answer helpful?

« Back