How to provide a password while executing `mysqldump` through shell script

I wrote a batch file which establishing the connection to linux server which I am able to do so, after this I am trying to take the mysqldump to some certain directory, it has all 777 permissions but linux system ask me to "Enter Password" which is nothing but empty, and manually I need to press Enter, I just need to execute my script which just press Enter so that execution will happen automatically. Below are some details.

batch file:

plink.exe -ssh user@host -m command.txt

command.txt:

mysqldump -uve -p -R -E --single-transaction --databases mydb|gzip > /home/user/mydb_bkup.gz

This is the image which is prompting me to enter password: this is the image which is prompting me to enter password

Please provide me some inputs so that I can enter the password and execute my command automatically.


As far as I understand you, it's the command you're running that asks for password. Your line is:

mysqldump -uve -p -R -E --single-transaction --databases mydb|gzip > /home/user/mydb_bkup.gz

If we head over to man mysql, we read the following:

The password to use when connecting to the server. If you use the short option form (-p), you cannot have a space between the option and the password. If you omit the password value following the --password or -p option on the command line, mysql prompts for one.

You have not specified anything - because the shell threats space as an argument separator. Either set a password for the mysql user, remove -p from the command.txt file, or... modify your command to the following:

mysqldump -uve --password="" -R -E --single-transaction --databases mydb|gzip > /home/user/mydb_bkup.gz

Here we explicitly specify a blank password.