创建Mysql自动备份任务

1. 创建用于Mysql备份任务的子账号

CREATE USER 'username'@'host'IDENTIFIED BY 'password';

2. 给子账号授权

GRANT ALL ON databasename.tablename TO 'username'@'host';

3. 给子账号授予导出sql权限

grant file on *.* to username ;

4. 创建一个执行脚本auto_backup.sh


#!/bin/bash

date_str=$(date +%Y%m%d_%H%M%S)

cd ~/backup

mysqldump -u backupuser --password=mysql kanga_mining > data/kanga_mining_$date_str.sql

echo backup_$date_str.sql OK

5.配置任务

vim auto_backup.cron
0 15 19 * * ? * ~/backup/auto_backup.sh
crontab ~/backups/auto_backup.cron > ~/backups/auto_backup.log

6.重启crontab服务查看任务

systemctl restart crond
crontab -l

你可能感兴趣的:(创建Mysql自动备份任务)