1 of 2

How to pass password to mysql command line

I have MySQL password saved on a file foo.txt, for example P455w0rd, when I try to use it:

$ cat foo.txt | grep 'mydb:' | cut -d ':' -f 2 | mysql -U root -p mydb -h friendserver
Enter password: (holds)

$ echo P455w0rd | mysql -u root -p mydb -h friendserver
Enter password: (holds)

Both option still ask for password, what's the correct way to send password from stdin?