How to Backup and or Restore your MySQL Database Using SSH
If you need to backup or restore your MySQL database via command line you can do the following to do so.
Backup MySQL Database
Connect via SSH and run MySQL
If you need to know how to connect to via SSH you can do so by following the below KB article:
- Connect to the server via SSH
- Type PWD, this will let you know what the directory you are working in
- To restore the SQL file the was uploaded you can run the below command:
mysqldump -u DATABASE_USERNAME -p DATABASE_NAME > FILENAME.SQL
Please note: The -p will prompt a user to enter the database password after the command is ran
- Once the MySQL dump has been completed the SQL file will be stored in the working directory
- Once this is completed without errors the command line will return to the below:
username@domain.com [~]#
- If you require a local copy of your database you can download it via FTP. Below is a KB article on how to connect via FTP:
How to Use FTP
Restore MySQL Database
There a two steps to restore a SQL backup via command line:
- Upload SQL file via FTP to server
- Connect via SSH and run MySQL
Upload SQL file via FTP to server
- Connect to the server via FTP
- Locate the SQL file on your local machine
- Upload the file to the home directory
cPanel:
Plesk 12.x
Connect via SSH and run MySQL
If you need to know how to connect to via SSH you can do so by following the below KB article:
- Connect to the server via SSH
- Type PWD, this will let you know what the directory you are working in
- To restore the SQL file the was uploaded you can run the below command:
mysql -uDATABASE_USERNAME -p DATABASE_NAME < FILENAME.SQL
Please note: The -p will prompt a user to enter the database password after the command is ran
-
Once this is completed without errors the command line will return to the below:
username@domain.com [~]#
Article ID: 2035, Created: September 24, 2014 at 10:48 AM, Modified: September 20, 2016 at 9:26 AM