Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-24-2009, 06:44 AM   #1
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
how to interact with mysql database using shell script

hi all...

I am new to linux... can anyone tell me how to interact mysql database using shell script......

thanks in advance...
Old 04-24-2009, 06:58 AM   #2
Senior Member
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
mysql --batch -u username -ppasswort -e "Show databases"

This will list all of the databases installed.
--batch : is just a reminder for mysql that it's called noninteractive
-u username : the username or maybe another
-ppassword: the password for the user. There should be no space between password an -p

mysql also has an option to not print the name of the columns but i can't recall it. Check out man mysql

Cheers Zhjim
Old 04-24-2009, 07:28 AM   #3
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Original Poster
Rep: Reputation: 55
thanks...this is fine this executes the only one statement ..and quits..
i want to execute series of statements in a shell script like

use mysql
insert user statement;
select * from user;
Old 04-24-2009, 08:46 AM   #4
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171
You're using the wrong tool ... "shell scripts" really were not designed for that.

And, in Linux, you don't have to try to "make that strategy work," because you probably have a half-dozen or more good programming environments at your beck and call ... any one of which can be used to write what appears to be "a shell script," thanks to the #!commandname ("shebang") mechanism.

Perl ... PHP ... Python ... Ruby ... Scheme ... others ... "pick your poison." It is very likely that most if not all of these are already installed, and if not, they can be installed in moments at no further cost to you.

When the shell is told to execute any file, it first determines whether the file is binary or text, and, if it is text, looks in the first line for the "shebang." It then silently invokes that program to carry out the script. It makes no visible difference to the user.

Welcome to Unix/Linux ... the programming tools paradise.


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: want to insert values in database when update script runs ring Programming 2 10-25-2007 11:48 PM
unix korn shell script that interact with windows java program ann124 Programming 5 11-09-2004 10:14 PM
Import records to MySQL Database from a shell script chrisk5527 Linux - General 12 03-24-2004 10:49 PM
How to interact with MYSQL database from within perl program Bassam Programming 5 02-26-2004 06:00 PM
Restoring MYSQL database without SSH shell access hct224 Linux - Newbie 5 01-08-2004 07:14 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:32 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration