0

My ultimate goal is to create a cron script to automatically dump a selected MySQL database (ngsRunStats_FK) once a day. Please note that the MySQL user ngs_run_stats has all privileges on MySQL.

I was expecting the answer from Franklin here would do the job, though when I run on the terminal

mysqldump --defaults-extra-file=/home/user/.my.cnf  -S /nexus/cliniphenome/mysql.sock -u ngs_run_stats -p ngsRunStats_FK --lock-tables=false > test.sql

I am still required to prompt my password. If I enter the password correctly, the dump will work as expected. Though, as stated previously, this should be done automatically i.e. without prompting for the password.

I am assuming that if I am being asked to prompt my password when I call the command on the terminal my cron (not shown here) script will not work. Or is this assumption wrong?

My /home/user/.my.cnf looks like so:

[mysqldump]
user = ngs_run_stats
password = mypassword

and has permissions 600

BCArg
  • 2,094
  • 2
  • 19
  • 37

2 Answers2

0

Try this:

mysqldump --defaults-extra-file=/home/user/.my.cnf  -S /nexus/cliniphenome/mysql.sock -u ngs_run_stats -pngsRunStats_FK --lock-tables=false > test.sql

there should be no space between -p flag and the input password.

However, note that this is an insecure way of connecting to your database as the password will be in plaintext within the command and can be visible through the logs.

Nasif Imtiaz Ohi
  • 1,563
  • 5
  • 24
  • 45
0

The mistake is that I am passing the -p flag, which will prompt the password. I misread the information from this website. So I should omit the -p flag and the database is actually specified by the --databases flag

mysqldump --defaults-extra-file=/home/user/.my.cnf  -S /nexus/cliniphenome/mysql.sock -u ngs_run_stats --databases ngsRunStats_FK --lock-tables=false > test4.sql
BCArg
  • 2,094
  • 2
  • 19
  • 37