Bash MySQL function

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

[code lang=”bash”]
# 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=`mysql –skip-column-names -h${dbhost} $db -u${dbuser} -e"${SQL}" -p${dbpass}`
return 0

This entry was posted in Code and tagged , , , .

Post a Comment

You must be logged in to post a comment.