Automatic Daily Backup for MySQL/MariaDB using MySQLDump

To automatically backup the MySQL or MariaDB database daily using MySQLDump, you can follow the steps below:

Create a backup script file

Create a script file (e.g., to contain the backup commands. Open a text editor and add the following commands to the script file:


# Replace the database connection information

# Path to the backup directory

# Create a backup file name with date format
BACKUP_FILE="$BACKUP_DIR/backup-$(date +%Y-%m-%d).sql"

# Use mysqldump command to backup the database

# Print a completion message when the backup is done
echo "Backup completed: $BACKUP_FILE"

Save the script file and ensure it has executable permissions. To do this, run the following command:

chmod +x


Set up an automatic backup job

Use the cron scheduler to set up a daily automatic backup job. Open the cron schedule by running the command:

crontab -e

Add the following line to the cron schedule file to set up a daily backup job at 2 AM:

0 2 * * * /path/to/

Save and close the cron schedule file.

The script will then be executed daily at 2 AM, and it will backup the MySQL or MariaDB database to the backup-YYYY-MM-DD.sql file in the specified directory.


Note that in the script, you need to replace username, password, and database_name with the actual login information and database name. Similarly, change /path/to/backup/directory to the actual backup storage directory path on your system.