LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-02-2010, 10:10 AM   #1
chirayu11
LQ Newbie
 
Registered: Jul 2010
Posts: 8

Rep: Reputation: 0
SQL Command output to bash variables


Hi,

I would like to run a bunch of SQL commands from mysql client in bash. However, I would like to store the output in different variables. E.g.

Code:
var1=`mysql -u[user] -p[pass] -D[dbname] -e "Query1"`
var2=`mysql -u[user] -p[pass] -D[dbname] -e "Query2"`
..
...
However, the trouble is that I provide my login details several times. Is there some way where I provide login just once, run commands and store their output in variables?

Thanks!
 
Old 08-02-2010, 10:20 AM   #2
johnshen64
LQ Newbie
 
Registered: Jun 2010
Posts: 29

Rep: Reputation: 5
you can put your login credentials in ~/.my.cnf
[client]
username=xxxx
password=xxx
 
Old 08-02-2010, 10:40 AM   #3
chirayu11
LQ Newbie
 
Registered: Jul 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Johnshen64, going by your way, I get an error:

Quote:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Any other way??
 
Old 08-03-2010, 08:53 AM   #4
johnshen64
LQ Newbie
 
Registered: Jun 2010
Posts: 29

Rep: Reputation: 5
sorry,

username should have been user.

make sure that the file is in the home directory of the user that is running your commands.
 
Old 08-04-2010, 06:35 AM   #5
chirayu11
LQ Newbie
 
Registered: Jul 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks a lot johnshen64, you're legend!!!
 
Old 08-04-2010, 08:40 AM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Then mark the thread as Solved (in Thread Tools).
 
  


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
Bash Script - Passing command string between variables Devcon Programming 13 01-10-2011 11:13 AM
[SOLVED] BASH: output of snmpget with multiple OIDs into separate variables shippropeller Programming 4 07-08-2010 01:50 AM
ps | grep command combination - Strange Output. Why Environment Variables Listed ? nkataria Linux - General 1 04-07-2010 04:50 AM
ambiguous output using variables in bash gwong Linux - Newbie 2 05-05-2007 09:49 PM
Command output conrolling in bash pazvant Linux - Software 1 10-24-2003 08:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:03 PM.

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