Back to Cron Helper
Recipedatabasemysqlbackupsql

Automate MySQL Backups Daily

Schedule a daily MySQL database dump using cron.

Use `mysqldump` to export your MySQL database into a SQL file. This command appends the current date to the filename, ensuring you have a history of backups. Running this daily at midnight ensures data safety with minimal disruption to active users.

Cron Schedule

Every Day at Midnight0 0 * * *
Runs once per day at 00:00 (midnight).

Command to Run

Copy and paste this command into your crontab or automation script

mysqldump -u username -p[password] dbname > /backups/db_$(date +%Y%m%d).sql
This command will run according to the cron schedule above.

Implementation Examples

Here are code examples for implementing this cron job in different programming languages:
Unix/Linux Crontab
0 0 * * * /path/to/script.sh
Python (with schedule library)
schedule.every().day.at("00:00").do(job)
Node.js (with node-cron)
cron.schedule('0 0 * * *', () => {
  console.log('Running daily at midnight');
});
Go (with robfig/cron)
c.AddFunc("0 0 * * *", func() { fmt.Println("Run daily at midnight") })
GitHub Actions Workflow
- cron: "0 0 * * *"

Related Cron Recipes

Automate PostgreSQL Backups Daily

How to schedule a daily PostgreSQL database backup using cron.
databasepostgresbackup

Automate MongoDB Backups Daily

How to schedule a daily MongoDB backup using cron.
databasemongodbbackup

Automate Redis RDB Snapshots

Schedule a Redis background save (snapshot) via cron.
databaserediscache

PostgreSQL Vacuum Analyze

Automate PostgreSQL database maintenance with VACUUM ANALYZE.
databasepostgresmaintenance

Sync Folder to AWS S3

Cron job to sync local files to an AWS S3 bucket.
awscloudbackup

Rsync Incremental Backup

Schedule secure, incremental backups using rsync.
linuxbackupnetwork