Zach wrote:
I am writing a shell script using Born Shell. I am trying to get the result of a SQL statement into a variable. For example:
/usr/bin/mysql -uroot -prootpass BOB << EOF SELECT * FROM Bobstable WHERE Name=1 EOF
How do I get the result into a variable?
But this is more a shell than a mysql question, isn't it ?
Nah, in fairness, it's more of a MySQL question because the issue is how you execute the 'mysql' command in such a way that it's conducive to the shell environment. I vote 60/40 MySQL vs. Shell.
> May be: > myvar=`/usr/bin/mysql -uroot -prootpass -e 'SELECT * FROM Bobstable > WHERE Name=1;' BOB`
Don't forget to use '-B' in order to make the output silent except for the results:
myvar=`/usr/bin/mysql -u root --password=password -B -e "SELECT ..."`
Naturally I'd be out of place not to mention the security implications: You should 1. not be querying your DB as the root database user if possible, and 2. you should stick your password (which shouldn't match your UNIX password) in a textfile readable only by you so that you don't pass the password on the command line.
-Fred
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]