LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-05-2008, 05:35 PM   #1
ThaSaltyDawg
LQ Newbie
 
Registered: Nov 2008
Location: Myrtle Beach, SC
Posts: 7

Rep: Reputation: 2
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!
 
Old 11-05-2008, 07:03 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Variable in Linux Bash for MySQL Query ThaSaltyDawg Linux - Newbie 7 04-13-2016 12:25 AM
I'm trying to get PHP to filter results from a MySQL query!!! Tom "Techno" Earl Programming 4 07-18-2011 07:49 AM
help with mysql query: return nth rows in query hawarden Programming 2 07-31-2006 07:36 PM
Samba force user, group doesn't return expected results tisource Linux - Software 1 12-13-2005 01:07 AM
PHP show query results Gerardoj Programming 1 05-11-2004 01:31 PM


All times are GMT -5. The time now is 11:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration