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