#!/bin/bash
# MySQL用户名和密码
USER="root"
PASSWORD="feifei520"
# 备份文件存放路径
BACKUP_DIR="./mysql_backup"
# 排除的数据库列表
EXCLUDE_DB="mysql information_schema"
# 获取所有数据库列表,排除系统数据库
DBS=$(mysql -u $USER -p$PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|${EXCLUDE_DB})")
# 备份每个数据库
for db in $DBS; do
echo "Backuping database: $db"
mysqldump -u $USER -p$PASSWORD --databases $db > $BACKUP_DIR/$db.sql
echo "Database $db backup completed"
done
发表评论 取消回复