CloudLinux.ro
Backup

How to back up a MySQL database, step by step

Updated 7/20/2026

A database without a backup is a problem waiting to happen. MySQL gives you the mysqldump tool for safe copies. Below you see how to make them, automate them and keep them safe on a Backup Box.

1. Manual backup with mysqldump

A single database, compressed:

mysqldump -u root -p mydb | gzip > mydb-$(date +%F).sql.gz

All databases:

mysqldump -u root -p --all-databases | gzip > all-$(date +%F).sql.gz

2. Restore

gunzip < mydb-2026-07-18.sql.gz | mysql -u root -p mydb

3. Automate with cron

Run the backup daily at 3 AM:

0 3 * * * mysqldump -u root -pPASSWORD mydb | gzip > /mnt/backup/mydb-$(date +\%F).sql.gz

Keep copies off-server, on a Backup Box

A backup on the same server does not save you if the server dies. A Backup Box gives you dedicated storage (1 TB - 20 TB) that you mount as an extra disk, so backups write straight there. You find the address, username and password on the Backup Box page in your panel.

Mount as an extra disk (SMB)

apt-get install -y cifs-utils
mkdir -p /mnt/backup
mount -t cifs //BACKUP_BOX_ADDRESS/backup /mnt/backup -o username=USER,password=PASSWORD,vers=3.0

Mount over SFTP (SSHFS)

apt-get install -y sshfs
sshfs -p 22 USER@BACKUP_BOX_ADDRESS:/ /mnt/backup

Once mounted at /mnt/backup, the cron script writes straight to the Backup Box. That way, even if the server disappears, your data is safe elsewhere. See also the general VPS backup guide.

Put this guide into practice on your own VPS

EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.

See pricing

Related tutorials