mysqldump 在 cron 中不起作用

2022-01-03 00:00:00 cron ubuntu mysql

首先,我在/home/username/ 中创建了 .my.cnf 并使用以下文本:

First, I created .my.cnf in /home/username/ with the following text:

<代码>[客户]用户 = 样本用户密码 = 样本密码主机 = 本地主机

然后,我执行了下面的命令,它成功了:

Then, I executed the command below and it went successfully:

/usr/bin/mysqldump sample_table >home/username/backup_db/$(date +%F)_full.sql

但是,当我在 crontabs 中输入它时,它不起作用:

But, when I entered it in crontabs, it didn't worked:

0 0 * * */usr/bin/mysqldump sample_table >/home/username/backup_db/$(date +%F)_full.sql

我什至尝试更改分钟和小时部分,但仍然无法正常工作.

I even tried changing the minutes and hour portion but still, it won't work.

推荐答案

您需要对百分号 (%) 进行转义,因为它在 crontab 条目中具有特殊含义,请改用 \%.

You need to escape the percent sign (%), as it has a special meaning in crontab entries, use \% instead.

相关文章