MySQL全库增量备份

定时执行(每晚23点)
0 23 * * * sh /root/data_backup/sql_backup.sh

脚本

#!/bin/bash
rm -rf ./backup.sql
rm -rf ./credentialsFile
echo "[client]" > ./credentialsFile
echo "user=root" >> ./credentialsFile
echo "password=Whz123..." >> ./credentialsFile
echo "host=127.0.0.1" >> ./credentialsFile
echo "port=3306" >> ./credentialsFile
mysqldump --defaults-extra-file=/root/shell/credentialsFile --all-databases > ./backup.sql

直接执行下面命令然后输入密码也可以备份
mysqldump -u root -h 127.0.0.1 -p --all-databases > /backup/allBackup.sql
Enter your password

脚本里执行报warning, 因为命令行里直接使用了密码, MySQL不推荐这样做.
mysqldump -u root -h 127.0.0.1 -p$PASSWD--all-databases > /backup/allBackup.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.