Tools

Back up and restore the MySQL database using the command line on Web Help Desk

This article describes how to back up and restore the external MySQL database using the command line.

First published date

7/12/2019 3:02 PM

Last published date

6/18/2020 7:28 PM

Overview

If you need to perform a backup and restore of the MySQl database via the command line, you may follow the steps provided on this article.

Product section

Web Help Desk

Cause

Need to to backup the MySQL database via the command line for MySQL database versions 5.6 or 5.7 on Web Help Desk.

Resolution

Back up the MySQL database


Windows Server

  1. Open a command prompt.
  2. In the window, execute:
    Go to the MySQL bin folder, 
    
    cd "C:\Program Files\MySQL\MySQL Server 5.6\bin" 
    
    or
    
     "C:\Program Files\MySQL\MySQL Server 5.7\bin"
  3. Back up the database. Execute:
    mysqldump --user=whd --password --default-character-set=utf8 --single-transaction --skip-set-charset --add-drop-database whd > C:\WHDMySQL\whdbackup.sql
  4. Enter  prompted for a database password. 

Linux or Virtual Appliance

  1. Download and start PuTTY or another SSHv2 client on your Windows PC
  2. Connect to the Linux server.
    If you are connecting to a virtual appliance, connect as the user admin. 
  3. In Linux, switch to root user or any user with sudo privileges.
    In the Virtual Appliance, enter sudo su.
  4. Back up the database. Execute:
    mysqldump -u whd -p -c -e --default-character-set=utf8 --single-transaction --skip-set-charset --add-drop-database -B whd > /data1/whdbackup.sql
    
    Note: /data1/ is a folder available on Linux WHD appliance, your backup folder may be different if using other CentOS installation. You may create your own backup folder.
    Enter the whd database user password if prompted for a database password.


Restore the MySQL database

Windows Server

  1. Open a command prompt.
  2. Go to the MySQL bin folder,

    cd "C:\Program Files\MySQL\MySQL Server 5.6\bin"

    or

    "C:\Program Files\MySQL\MySQL Server 5.7\bin"
  3. Restore the database.
    Execute:
    mysql -u whd -p whd < C:\whdbackup.sql
  4. Enter the whd database user password if prompted for a database password.

Linux or Virtual Appliance

  1. Connect to the Linux server.
    If you are connecting to a virtual appliance, connect as the user admin.
  2. Connect to the Linux server.
    If you are connecting to a virtual appliance, connect as the user admin. 
  3. In Linux, switch to root user or any user with sudo privileges.
    In the Virtual Appliance,enter sudo su.
  4. Restore the database. Execute:
    mysql -u whd -p whd < /data1/whdbackup.sql
    Enter whd database user password if prompted for a database password.

Disclaimer: Scripts are not supported under any SolarWinds support program or service. Scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.