How to back up a MySQL database, step by step
Updated 10/16/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 pricingRelated tutorials
Automated database backups with Portabase and a Storage Box
Set up Portabase to back up your databases and push the copies to a cloudlinux.ro Storage Box, in a separate location.
Updated 10/16/2026BackupHow to back up a Laravel application, step by step
A complete Laravel backup: code, .env, storage and database, plus how to send it all to a Backup Box mounted as an extra disk.
Updated 10/16/2026BackupHow to back up a PostgreSQL database, step by step
A complete PostgreSQL backup guide: pg_dump, cron automation and how to send copies to a Backup Box mounted as an extra disk.
Updated 10/16/2026