I have tried to make backup cron job on my webserver running FreeBSD. Currently it looks something like this:
/usr/local/bin/mysqldump --opt --single-transaction --comments --dump-date --no-autocommit --all-databases --result-file=/var/backups/mysql/all.sql
It works fine when I run it as root (since root has a .my.cnf
with the username and password used to connect, but when the job is run by cron, the my.cnf
file is not read.
Is there any way around that without having to put username and password into the command itself (since that's kinda insecure)?
Strangely, I have the same setup with PostgreSQL and a .pgpass
file, and that works like a charm.
Use the --defaults-extra-file
option to tell it where to find the .my.cnf
file (assuming it's readable by whichever user is running mysqldump
.