Backup your database (MySQL) using rescue mode


In certain cases (Server does not work in NORMAL mode, forced reinstallation, etc …) you may need to backup your database directly from rescue mode.

MySQL stores all data related to a database in a folder for each database, located at /var/lib/mysql.

Backup your database

Once the server is booted into rescue mode, start by mounting the partitions:

mdadm: md device /dev/md0 does not appear to be active.
/dev/sda3 ressemble à un espace de SWAP et ne sera donc pas monté.
/dev/md0 ne peut être monté.
/dev/sda1 vient d'être monté dans /mnt/sda1
/dev/sda2 vient d'être monté dans /mnt/sda2

Normally, the first mount point corresponds to your boot partition.

If you have kept the default partition layout during the installation, your valuable data will be on the second partition.

It is mounted as /mnt/sda2 in our example.

If required, you can directly backup the whole directory /mnt/sda2/var/lib/mysql or a specific folder inside it, if you want to backup a single database only.

Using a Linux computer

It is for example possible to backup your data using SCP.

scp -r ~

This will backup the MySQL folder on the mounted partition to the home folder of the user logged into your computer.

Using a Windows computer

You use directly the SFTP protocol with FileZilla.

These are the elements you need for the connection:

  • Host: s (the IP address of your server)
  • Username: name of your user
  • Password: your password (available in your Console)
  • Port: 22

Once you are connected, you can see the files on your server in the area on the right, navigate to the folder /mnt/sda2/var/lib/mysql and double-click on the directory that you want to download to your computer.

Restore your database

To restore your data, simply upload the folder to your new installation by doing these tasks vice-versa.

Don't forget to restore the required permissions to the folder, if you have made the modification directly from the root account: chown -R mysql:mysql /var/lib/mysql/XXXX