How to Connect To MySQL or Oracle Database Using Shell Scripting

I am Working on a Small Projects Using the Language shell scripting.
But I can't connect or link to database using shell scripting..
Please Help me Out.
Thank You....
MRUTYUNJAYA GIRIAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
which shell script are you using,

you would need to use sqlplus for oracle and send commands and assign results,
for access to mysql you would use mysql ..
There are several references
http://www.oracle.com/technetwork/articles/linux/saternos-scripting-088882.html

For mysql
http://blog.mclaughlinsoftware.com/2015/05/17/bash-arrays-mysql/
0
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NTCommented:
Sample script for automation:
#!/bin/ksh
echo "SELECT TNAME FROM TAB;" |\
/u01/app/oracle/product/11.2.0/dbhome_2/bin/sqlplus Username/Password@Hostname:Port/ServiceName 2>&1|\
/bin/egrep -v "^SQL|^$"
# Commented line
# Write related full path of /u01/app/oracle/product/11.2.0/dbhome_2/bin/sqlplus

Open in new window

Inside the script
You can remove required strings which is not required:
echo "SQL
test
blank

last" |\
/bin/egrep -v "^SQL|^$"

Open in new window

Removing lines beginning with SQL => ^SQL
and removing blank lines => ^$ => Begins with => ^, ends with => $
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NTCommented:
Provided and tested the proposed command.
Resolving this query.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.