To use a MySQL query in a script, you can do so like this:
#!/bin/bash
echo “use testdb; select Name, Address from Users;” | mysql -h testdb.testdomain.com -utest -ptestpass > myoutputfile
You can then parse “myoutputfile” and do whatever you’d like with it.