Skip to main content
remove unsalvageable typo
Source Link
Alois Mahdal
  • 4.6k
  • 13
  • 45
  • 65

Stephane's answer is the best way how to do it for mysql case. And in most cases using the program's "own" way is the best.

However, to answer the Bash part of your question:

mysqldump -u joe -p <<<"joe's pasword" > /path/to/backup/file

or (less insecure)

mysqldump -u joe -p </path/to/file/with/joes/password > /path/to/backup/file

This approach will simply pass the (anu) string to the mysqldump process. It will work, provided that:

  • the password is only thing it asks,

    ie. there's no other prompt (most commands are quite predictable);

  • it will accept password from STDIN even if it's not interactive,

    ie. the program can deliberately verify if the file on input is an interactive terminal and abort.

Stephane's answer is the best way how to do it for mysql case. And in most cases using the program's "own" way is the best.

However, to answer the Bash part of your question:

mysqldump -u joe -p <<<"joe's pasword" > /path/to/backup/file

or (less insecure)

mysqldump -u joe -p </path/to/file/with/joes/password > /path/to/backup/file

This approach will simply pass the (anu) string to the mysqldump process. It will work, provided that:

  • the password is only thing it asks,

    ie. there's no other prompt (most commands are quite predictable);

  • it will accept password from STDIN even if it's not interactive,

    ie. the program can deliberately verify if the file on input is an interactive terminal and abort.

Stephane's answer is the best way how to do it for mysql case. And in most cases using the program's "own" way is the best.

However, to answer the Bash part of your question:

mysqldump -u joe -p <<<"joe's pasword" > /path/to/backup/file

or (less insecure)

mysqldump -u joe -p </path/to/file/with/joes/password > /path/to/backup/file

This approach will simply pass the string to the mysqldump process. It will work, provided that:

  • the password is only thing it asks,

    ie. there's no other prompt (most commands are quite predictable);

  • it will accept password from STDIN even if it's not interactive,

    ie. the program can deliberately verify if the file on input is an interactive terminal and abort.

Source Link
Alois Mahdal
  • 4.6k
  • 13
  • 45
  • 65

Stephane's answer is the best way how to do it for mysql case. And in most cases using the program's "own" way is the best.

However, to answer the Bash part of your question:

mysqldump -u joe -p <<<"joe's pasword" > /path/to/backup/file

or (less insecure)

mysqldump -u joe -p </path/to/file/with/joes/password > /path/to/backup/file

This approach will simply pass the (anu) string to the mysqldump process. It will work, provided that:

  • the password is only thing it asks,

    ie. there's no other prompt (most commands are quite predictable);

  • it will accept password from STDIN even if it's not interactive,

    ie. the program can deliberately verify if the file on input is an interactive terminal and abort.