Restoring a Database using SSH

phpMyAdmin is useful but for database imports it has a maximum file size of 20MB. Fortunately it is almost as fast to use ssh to get the job done.

Steps to import a MySQL DB using SSH
1) Get the backup from host or export from current db (typically these are in a sql.gz format so they need to be unzipped first)
2) Use SFTP to move the file to your home directory on the server
3) If the file is zipped, using an SSH terminal type:

gunzip mysqlbackup.sql.gz

This will cause file to be unzipped, so now "mysqlbackup.sql" will be sitting in your home directory.
4) When you are ready to import the backup (After you have made sure to make a copy of the DB you are overwriting) type this in the ssh terminal

mysql -h localhost -u USERNAME -p DATABASENAME < mysqlbackup.sql

This will replace the current database named DATABASENAME with the database defined in mysqlbackup.sql

5) You will be prompted for the database password (not your terminal password) For the db username and password, if it is a Drupal site, you can get that by looking in settings.php in the drupal folder for the site.

Backing up a Database

1) ssh to your dev on the saturn or cairo
2) run

mysqldump -h localhost -u USERNAME -p DATABASENAME > mysqlbackup.sql

It will create the backup file in whatever directory you were in.

section: