Bash SQL Query Helper

What is Bash SQL Query Helper?

This script is a very simple script that helps one to run sql commands from the command line with the command name and the query as opposed to running all sorts of switches. This is definately not a complicated script and there are probably some security considerations around using such a script with certain fields saved in it. But the main goal is to be able to call the mysql client to give me a result set as simple as possible.

The Query Helper Script

if [ -z "$1" ];then
echo "Needs Sql Command to run" ;
exit 0 ;
if [ -z "$PASSWORD" ]; then
echo "Command: echo "$1"" | $SQL -u$USER $DATABASE"" ;
echo ""$1;""| $SQL -u$USER $DATABASE
echo ""Command: echo ""$1"" | $SQL -u$USER --password=$PASSWORD $DATABASE"" ;
echo ""$1;""| $SQL -u$USER --password=$PASSWORD $DATABASE

So essentially what we are doing here is saving a couple of parameters inside this script like user, password and database; then passing the query string which is parameter 1 to the sql client binary. There is barely any error checking and this definately should not be used on a production server as it contains the password in plain text.


About ttessier

Professional Developer and Operator of SwhistleSoft
This entry was posted in Bash Scripting. Bookmark the permalink.

Leave a Reply

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