mysqldump doesn't work in crontab

前端 未结 9 2139
我寻月下人不归
我寻月下人不归 2020-12-08 21:26

I\'m trying to add a cronjob in the crontab (ubuntu server) that backups the mysql db.

Executing the script in the terminal as root works well, but inserted in the c

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 21:38

    I was trying the same but I found that dump was created with 0KB. Hence, I got to know about the solution which saved my time.

    Command :

    0 0 * * * mysqldump -u 'USERNAME' -p'PASSWORD' DATEBASE > /root/liveDB_`date +\%Y\%m\%d_\%H\%M\%S`.sql
    

    NOTE: 1) You can change the time setting as per your requirement. I have set every day in above command.

    2) Make sure you enter your USERNAME, PASSWORD, and DATABASE inside single quote (').

    3) Write down above command in Crontab.

    I hope this helps someone.

提交回复
热议问题