Shell script to select and insert values from mysql.

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2009
Posts: 3
Reputation: zoollu is an unknown quantity at this point 
Solved Threads: 0
zoollu zoollu is offline Offline
Newbie Poster

Shell script to select and insert values from mysql.

 
0
  #1
Mar 10th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

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

 
0
  #2
Mar 11th, 2009
Originally Posted by zoollu View Post
... 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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 3
Reputation: zoollu is an unknown quantity at this point 
Solved Threads: 0
zoollu zoollu is offline Offline
Newbie Poster

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

 
0
  #3
Mar 12th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

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

 
0
  #4
Mar 12th, 2009
Originally Posted by zoollu View Post
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 3
Reputation: zoollu is an unknown quantity at this point 
Solved Threads: 0
zoollu zoollu is offline Offline
Newbie Poster

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

 
0
  #5
Mar 12th, 2009
works great. thank you
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC