This is really just a supplementary answer to the others. I'd add it as a comment if I was allowed.
It's also not a very good practice because it puts the password in plaintext which you should never do if you can avoid it. A mysql config file is at least more easily protected than a script.
The answer that I'm avoiding is: Expect scripting. Using Expect script, your bash script runs within Expect which waits for (Expected) input matching it's rule and then responds with the (desired) output.
It's really just Expecting 'password:' and then responding with "myplaintextpassword\r". It was designed to allow scripts on one server to perform interactive ssh sessions on a different server.
Here's a question that covers the topic: Expect ScriptingExpect Scripting.
Expect is easily installed on any Linux distribution.