I am trying to retrieve email address from MySQL database.
#!/bin/bash
MYSQLHOST="192.168.1.1"
MYSQLDB="nuni"
MYSQLUSER="root"
MYSQLPASS="rootpass"
MYSQLOPTS="--user=${MYSQLUSER} --password=${MYSQLPASS} --host=${MYSQLHOST} ${MYSQLDB}"
EMAIL=echo "SELECT email FROM Edsrn WHERE userid = 1235" | mysql ${MYSQLOPTS}
echo "E-mail: $EMAIL"
What is wrong with it? I says “command not found”. Please help!
I recommend using the
-eparameter to evaluate SQL statements instead. This should be what you’re looking for:Note the
tailis needed since the output from mysql looks like this: