database

How do I run a MySQL query in a script?

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.

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

To Top