In this article I will explain how to backup and restore a MySQL database from command line using Drush.
Drush is a command line shell and Unix scripting interface for Drupal.
I will backup the databse from site A and import it into site B.
We are going to use the commands:
sql-dump: Exports the Drupal DB as SQL using mysqldump or equivalent.
sql-cli: Open a SQL command-line interface using Drupal's credentials.
Site A
Back up the database using the sql-dump command.
drush sql-dump > ~/mysql_file.sql
The command above will create a database backup in a file placed in you home directory. You can change the destination and the file changing the part ~/mysql_file.sql.
Site B
Import the databse using the command sql-cli.
drush sql-cli < ~/mysql_file.sql
The command above will import the database.