«

»

Print this Post

Bash MySQL function

I use this function to run SQL queries from bash scripts.

fRunQuery(){
# This function should always be preceeded by a SQL statement
# Loaded into the variable SQL
# ie) SQL="SELECT * FROM table"; fRunQuery
# The results of the query will be loaded into the variable
# $RESULT:
RESULT=`mysql --skip-column-names -h${dbhost} $db -u${dbuser} -e"${SQL}" -p${dbpass}`
return 0
}

Permanent link to this article: http://www.lukemacneil.com/2010/04/26/bash-mysql-function/

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>