Mysql – Are certain environment variables required for thesql login-path

cronMySQLmysqldump

I created a bash script that backs up my database, db_backup.sh

It basically just runs these commands:

DB=/home/linuxuser/backups/backupfilename.sql.gz
mysqldump --login-path=local db_name | gzip > "$DB"

When I run it from the command line as linuxuser or as root, it works.

But when I add it to cron.d, I get a mysql error and the sql.gz file is empty.

mysqldump: Got error: 1045: Access denied for user 'linuxuser'@'localhost' (using password: NO) when trying to connect

(I get the same type of error when running the cron as root, too)

How can I fix this? Could it be a problem with environment variables?

I tried changing:

HOME=/

to

HOME=/linuxuser/

… but that did not help.

Best Answer

mysqldump needs -u and -p for some mysql "user".

Related Question