Bash MySQL function

| April 26, 2010 | Reply

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
}

Tags: , , ,

Category: Uncategorized

About the Author ()