943,960 Members | Top Members by Rank

Ad:
Mar 10th, 2009
0

Shell script to select and insert values from mysql.

Expand Post »
Hi,

I am familiar with shell script but not really have much experience. I am looking into a shell script that would do this

I have 2 tables

TableA

id name interest
----------------------------------------
TableB

id name

I have to create a shell script which copies all the id,name values from TableA and inserts them in TableB.

Is this possible? Any help is appreciated.

thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zoollu is offline Offline
3 posts
since Mar 2009
Mar 11th, 2009
0

Re: Shell script to select and insert values from mysql.

Click to Expand / Collapse  Quote originally posted by zoollu ...
... I have to create a shell script which copies all the id,name values from TableA and inserts them in TableB.

Is this possible? Any help is appreciated.

thanks
To misquote an old TV show, "Of course it's possible; don't be ridiculous." And it's really trivial.

You could try something like:
Shell Scripting Syntax (Toggle Plain Text)
  1. mysql -u username -e 'insert into TableB select col1,col2 from TableA;'
You have to enter the password manually; if it needs to run unattended, you can include the '-p password' option on the command line.
Reputation Points: 51
Solved Threads: 35
Posting Whiz in Training
Fest3er is offline Offline
238 posts
since Aug 2007
Mar 12th, 2009
0

Re: Shell script to select and insert values from mysql.

thank you I got that. its working fine. How do I check if any error occurred during execution. If an error occurred I would like to do a different operation.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zoollu is offline Offline
3 posts
since Mar 2009
Mar 12th, 2009
0

Re: Shell script to select and insert values from mysql.

Click to Expand / Collapse  Quote originally posted by zoollu ...
thank you I got that. its working fine. How do I check if any error occurred during execution. If an error occurred I would like to do a different operation.
Shell Scripting Syntax (Toggle Plain Text)
  1. mysql -u ...
  2. if [ $? -eq 0 ]; then
  3. echo "Success"
  4. else
  5. echo "Failure"
  6. fi
Reputation Points: 51
Solved Threads: 35
Posting Whiz in Training
Fest3er is offline Offline
238 posts
since Aug 2007
Mar 12th, 2009
0

Re: Shell script to select and insert values from mysql.

works great. thank you
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zoollu is offline Offline
3 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: A second bash to auto-run as non-root user
Next Thread in Shell Scripting Forum Timeline: Recommended books for mastering Windows Scripting?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC