Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I wrote a simple shell script to dump a specific mysql database. problem is it is prompting me for a password even though I provide on. The mysql db is version 5.0.27 if that matters. Here is the specific line I am using.

$MYSQLDUMP -u backup -p$MyPass $DB > $DEST/$FILE

I tried several variations, but to no avail.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

I would wager that $MyPass is not being set properly in your script. If any of the mysql command-line tools receive a -p that is not immediately followed by a password, they assume they should prompt for the password. If, on the other hand, you supplied an incorrect password (or the wrong username or similar) it would just fail to connect.

So, I suggest placing an echo command at the start of that line and re-running your script, like so:

echo $MYSQLDUMP -u backup -p$MyPass $DB

Don't forget to remove the output redirection.

share|improve this answer
    
doh, it was the stupid variable, had pass in caps when it was set vs lowercase in the above line. thanks guys –  aduljr Aug 19 '09 at 20:51
add comment

A better solution would be to store the username and password in a configuration file and point to that configuration file. By having it in the command line anyone who can run ps could find the password for your server.

Pass the --defaults-extra-file=/pathto/database.cnf to mysql dump.

The configuration file needs to look like this. Set the filesystem permissions so that only the backup process can open the configuration file.

[client]
host     = servername.domain.tld
user     = backup
password = strongpassword
share|improve this answer
    
its a specific user for that database with only enough permission to perform a backup. Only two people have access to this server, my and one other person. But I will make use that that cnf file idea. never knew about that option. thanks –  aduljr Aug 19 '09 at 20:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.