How does "mysql" ask for a password? How does "mysql" ask for a password? unix unix

How does "mysql" ask for a password?


Open /dev/tty as a file in read-mode, and then read from it.


Passwords are usually read directly from the terminal. In fact, there's a function getpass that does just this.


When you pipe in a file, it comes on stdin. Applications that read passwords usually open up a separate input stream.

The best way to accomplish your goal is to use Expect.

#!/usr/bin/expect -fspawn mysqlexpect "*password*"send "your_password_here"