How to export/import a MySQL database via SSH

If you have a large database, you may face the issue to export/import large SQL database using phpMyAdmin or other interface.

WHMCS Complete Billing and Support

In this article we will show you how to export/import SQL database via SSH. You can follow this steps if you have SSH access for your account.

1. Exporting a MySQL database via SSH

To export your MySQL database, you need to use mysqldump command. You need to execute following command to export your database:

mysqldump -uUSERNAME -pPASSWORD DATABASE_NAME > DATABASE_BACKUP.sql

In the above command, you will have to update following details:

USERNAME = Your MySQL database user which has full permissions on your database
PASSWORD = Your MySQL database user’s password
DATABASE_NAME = Database name which you would like to backup

Above command will export your MySQL database in DATABASE_BACKUP.sql file. You can specify any file name.

2. Importing a MySQL database

To import your MySQL database via SSH, you need to use mysql command. You need to execute the following command to import your MySQL dump to a database:

mysql -uUSERNAME -pPASSWORD DATABASE_NAME < DATABASE_BACKUP.sql

In the above command, you will have to update following details:

USERNAME = Your MySQL database user which has full permissions on your database
PASSWORD = Your MySQL database user’s password
DATABASE_NAME = Database name which you would like to backup

If your backup file is uploaded in the different location, make sure that you specify the exact path for your database backup (i.e. /home/<user>/backup/DATABASE_BACKUP.sql).

Posted in MySQL.

Leave a Reply

Your email address will not be published. Required fields are marked *