How to Export or Import a MySQL Database from shell

Shell or Telnet or SSH is something that any system administrator can not live without.  It's a necessary lifeline when it comes to VPS and Dedicated Servers.  If your host doesn't offer it, switch to Hands-on Web Hosting as it will make your life much easier when doing routine tasks such as backing up a database, copying a database or importing a database.

Dealing with databases all day long in the eComemrce world we are constantly importing SQL files or making backups for users for whatever reason, shell is the easiest (and fastest) way to do this.

To export a database we use the command "mysqldump":

mysqldump -u username -ppassword database_name > file.sql

If you are ROOT you can do something simple like:

mysqldump database_name > file.sql

To import a database we use just the straight command "mysql" command:

mysql -u username -ppassword database_name < file.sql

Or if you are logged in as root you can do just:

mysql database_name < file.sql

The database MUST exist if you run this process for the import.

reviewed: 10/27/2016

  • Email, SSL
  • 9 Users Found This Useful
Was this answer helpful?

Related Articles

How do I find my root password?

1) Log into your billing account: 2) Click on the...

How to generate a CSR in WHM

You would like to purchase or transfer an SSL certificate but need a CSR to do so. Here's how to...

Changing ip addresses

To move an account from one ip to another in WHM:1) Log into WHM using root login details....

-DELETE How to downgrade MySQL from Version 5 to Version 4

If you've upgraded your MySQL Software to the newest version but for whatever reason need to...

How to disable Recursive DNS Lookups

A very common PCI Issue is related to the DNS servers.  In order to be PCI Compliant you must...