LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 04-24-2009, 05:44 AM   #1
vinaytp
Member
 
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, 05:58 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,436
Blog Entries: 11

Rep: Reputation: 181Reputation: 181
Code:
#!/bin/bash
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, 06:28 AM   #3
vinaytp
Member
 
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;
etc...
 
Old 04-24-2009, 07:46 AM   #4
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,230

Rep: Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071Reputation: 1071
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.
 
  


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


All times are GMT -5. The time now is 10:47 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration