How to Backup and or Restore your MySQL Database Using SSH

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:
  1. Connect to the server via SSH
  2. Type PWD, this will let you know what the directory you are working in
  3. 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
  4. Once the MySQL dump has been completed the SQL file will be stored in the working directory
  5. Once this is completed without errors the command line will return to the below:
    username@domain.com [~]#
  6. 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

  1. Connect to the server via FTP
  2. Locate the SQL file on your local machine
  3. 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:
  1. Connect to the server via SSH
  2. Type PWD, this will let you know what the directory you are working in
  3. 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
  4. Once this is completed without errors the command line will return to the below:
    username@domain.com [~]#
     

Add Feedback