Importing/Exporting Databases from Command Line

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, don't hesitate to reach out to our support staff!

  • cpanel, domain, hosting
  • 0 Els usuaris han Trobat Això Útil
Ha estat útil la resposta?

Articles Relacionats

DNS Management - How To Edit MX Records

DNS Management - How To Edit MX Records A mail exchanger (MX) record is a type of DNS record...

Cpanel Exim How To Clear The Mail Queue

  Cpanel Exim How To Clear The Mail Queue Here’s the proper way to clear the exim mail...

Creating a cPanel User Account

Creating a cPanel User Account To create a new account go toWHM >> Account Functions...

How can I limit access to certain directories on my server by requiring a password using cPanel/WHM?

How can I limit access to certain directories on my server by requiring a password using...

How do I backup my entire site in Cpanel?

How do I backup my entire site in Cpanel? Entire accounts can be backed up by doing the...