LinuxQuestions.org
Visit Jeremy's Blog.
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 07-26-2012, 04:13 AM   #1
Owais.Ahmad
LQ Newbie
 
Registered: Jul 2012
Posts: 10

Rep: Reputation: Disabled
How to access database through shell script


Hi,

I'm new to linux, I'm using Red Hat version 5. I have lamp installed in my system i want to retrieve database through shell script. My shell script's code is :

#!/bin/sh
clear

/opt/lampp/lampp start
/opt/lampp/bin/mysql -u root -p

This code opens the mysql client. But i want a script which displays the tables in the database. Can anyone help me with this????

Regards,

Owais
 
Old 07-26-2012, 04:19 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
http://www.cyberciti.biz/faq/run-sql...-command-line/
 
Old 07-26-2012, 04:32 AM   #3
Owais.Ahmad
LQ Newbie
 
Registered: Jul 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
well i want table in the database to be displayed on the command terminal.
 
Old 07-26-2012, 04:54 AM   #4
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Hi,

the first is what "pan64" has given you the link
the second I'm adding is
here

so you need to "use database" and "show tables" afterwards.

Here's the "one-line" code for showing databases:
Code:
#!/bin/sh
echo "show databases;" | /usr/bin/mysql -u root -p"password"



The output:
Database
information_schema
horde
mysql
postfix
test
and here listing the tables in "mysql" database:
Code:
echo "use mysql; show tables;" | /usr/bin/mysql -u root -p"password"


Output:
Tables_in_mysql
columns_priv
db
func
help_category
help_keyword
help_relation
help_topic
host
proc
procs_priv
tables_priv
time_zone
time_zone_leap_second
time_zone_name
time_zone_transition
time_zone_transition_type
user

Last edited by lithos; 07-26-2012 at 05:05 AM.
 
1 members found this post helpful.
Old 07-26-2012, 05:12 AM   #5
Owais.Ahmad
LQ Newbie
 
Registered: Jul 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thank you, it Worked
 
  


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
Shell Script to insert value in database deepu_linux Programming 14 04-25-2013 01:07 PM
Checking Database it running or not by using shell script ramslinux Linux - Software 4 07-21-2011 03:04 PM
Database connection using Shell Script sumitarun Linux - Newbie 2 05-09-2010 01:18 PM
Shell Script: want to insert values in database when update script runs ring Programming 2 10-25-2007 11:48 PM
Restoring MYSQL database without SSH shell access hct224 Linux - Newbie 5 01-08-2004 07:14 AM


All times are GMT -5. The time now is 09:49 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