LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Query MySQL in Bash return multiple results (https://www.linuxquestions.org/questions/linux-newbie-8/query-mysql-in-bash-return-multiple-results-681371/)

ThaSaltyDawg 11-05-2008 04:35 PM

Query MySQL in Bash return multiple results
 
How put the following mysql results into an array?

USER=`mysql -h host --user=myuser --password=mypass MYDB -e "SELECT UserID FROM Users WHERE HireDate > $tDate;"`

Then Loop

while [ ... ]; do
$users = "$USER;"
done

Basically trying to concatenate it into a string delimited by ";"

Now once I get the array how do I list it into a log file
cat >> /home/me/users/users.log << EOF
$USER
EOF

I know the syntax is ugly but I really have no clue, well very little clue.

And thanks for your help!

chrism01 11-05-2008 06:03 PM

See concat_ws : http://dev.mysql.com/doc/refman/5.0/...functions.html
Then just echo $USER to the logfile.
Note, use 'echo' to read vars, 'cat' to read files.

http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
http://rute.2038bug.com/index.html.gz

PS If you're going to be doing a lot of DB manipulation, use a better lang eg Perl.
Shell would work, but its doing it the hard way.


All times are GMT -5. The time now is 03:55 AM.