#!/bin/bash
# MySQL credentials
USER="root"
PASSWORD="xxx你的密码"
HOST="xxx你的地址"
# Directory to save backups
BACKUP_DIR="/mysql_backup"
# Get the list of databases excluding the default ones
databases=$(mysql -u$USER -p$PASSWORD -h$HOST -e "SHOW DATABASES;" | grep -Ev "^(Database|mysql|information_schema|performance_schema|sys)$")
# Loop through each database and back it up
for db in $databases; do
echo "Backing up $db..."
mysqldump --single-transaction --quick --lock-tables=false --no-data --databases $db --user=$USER --password=$PASSWORD --host=$HOST > $BACKUP_DIR/$db.sql
done
echo "Backup complete!"