#!/bin/bashUSER=root #用户PASSWORD=123456 #密码MYSQL_PATH=127.0.0.1 #地址MYSQL_BIN=/bin/mysql MYSQL_DUMP_BIN=/bin/mysqldumpMYSQL_CMD="${MYSQL_BIN} -u${USER} -p${PASSWORD} -h${MYSQL_PATH}"DATABASE=($(${MYSQL_CMD} -e "show databases;"|egrep -v "Database|mysql|test|information_schema"))BACKUP_DIR=/data/mysql_backup/$(date +%Y-%y-%d) #备份目录[ -d ${BACKUP_DIR} ]||mkdir -p ${BACKUP_DIR} for database in ${DATABASE[@]};do echo $database BACKUP_DATABASE_DIR=${BACKUP_DIR}/${database} [ -d ${BACKUP_DATABASE_DIR} ]||mkdir -p ${BACKUP_DATABASE_DIR} for table in `${MYSQL_CMD} -e "use ${database};show tables;"`;do ${MYSQL_DUMP_BIN} -u${USER} -p${PASSWORD} -h${MYSQL_PATH} ${database} ${table} >${BACKUP_DATABASE_DIR}/${table}.sql donedone