bash,#!/bin/bash,# 定义变量,BACKUP_DIR="/backup/mysql",MYSQL_USER="root",MYSQL_PASSWORD="yourpassword",DATABASE_NAME="yourdatabase",DATE=$(date +%Y%m%d%H%M),,# 创建备份目录,mkdir -p $BACKUP_DIR,,# 执行备份,mysqldump -u$MYSQL_USER -p$MYSQL_PASSWORD $DATABASE_NAME > $BACKUP_DIR/$DATABASE_NAME-$DATE.sql,,# 检查备份是否成功,if [ $? -eq 0 ]; then, echo "Backup successful: $BACKUP_DIR/$DATABASE_NAME-$DATE.sql",else, echo "Backup failed",fi,
`,,请根据实际情况修改
MYSQL_USER、
MYSQL_PASSWORD 和
DATABASE_NAME`。