LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 08-23-2011, 09:07 AM   #1
Soma123
LQ Newbie
 
Registered: Aug 2011
Posts: 3

Rep: Reputation: Disabled
Wink Mysql Connectivity from shell script


hi,

I want a database connectivity to mysql server from Shell script
so plz tell me the one program that will access the database from shell script


Thanks in advance....
 
Old 08-23-2011, 09:31 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,477

Rep: Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970
Quote:
Originally Posted by Soma123 View Post
hi,
I want a database connectivity to mysql server from Shell script so plz tell me the one program that will access the database from shell script
Thanks in advance....
Spell out your words.

And since you don't say what you want to do, or give any ideas as to your needs/goals, then you need to use the "mysql" command. Read the man pages.
 
Old 08-23-2011, 06:45 PM   #3
allwimb
Member
 
Registered: Aug 2011
Posts: 47

Rep: Reputation: Disabled
use the mysql command like this :
mysql -u myuser -p mydb

if the user 'myuser' has a password you'll need to use the -p option else you've to remove it.

spring logout

Last edited by allwimb; 12-12-2011 at 05:47 AM.
 
Old 08-23-2011, 11:54 PM   #4
Soma123
LQ Newbie
 
Registered: Aug 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Wink Database connectivity with shell script

Hi,

i have writtn a one shell script that takes input values from keyboard and now i have to store that values in the database
so i need database connectivity from shell script so that i can insert values into database?

So plz help...

Thanks in advance
 
Old 08-24-2011, 12:52 AM   #5
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Rep: Reputation: Disabled
You could get more help if you share your script with the members and then ask for help with the script or with some modifications in it. Without your script and any information on what you want to do or what information you want to store, its like firing a gun in the dark.
 
Old 08-24-2011, 12:59 AM   #6
Soma123
LQ Newbie
 
Registered: Aug 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Smile Database connectivity with shell script

My script looks like this and i want to insert values into database through shell script

#!/bin/bash
name="Abc"
address="Delhi"
no="123456789"
#Database name is My_Db
#Table name:info_table

mysql -u root -p 'root' My_Db <<EOFMYSQL
insert into info_table values ($name,$address,$no);
EOFMYSQL

Last edited by Soma123; 08-24-2011 at 01:00 AM. Reason: add information
 
Old 08-24-2011, 09:54 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,477

Rep: Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970
Quote:
Originally Posted by Soma123 View Post
My script looks like this and i want to insert values into database through shell script
Code:
#!/bin/bash
name="Abc"
address="Delhi"
no="123456789"
#Database name is My_Db
#Table name:info_table

mysql -u root -p 'root' My_Db <<EOFMYSQL
insert into info_table values ($name,$address,$no);
EOFMYSQL
Again, spell out your words, and READ THE MYSQL MAN PAGE. Pay particular attention to the "-e" switch, which will let you put your insert statement onto the same line with your mysql call.

And you don't tell us what error(s) you're getting when you run the script above, so it's hard for anyone to help you.
 
  


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 for testing connectivity via URL saurabhmehan Linux - Newbie 2 08-05-2010 11:27 AM
MySQL Updates With Null When Perl Script Run From Shell Script ThisGuyIKnow Programming 6 08-12-2008 09:56 AM
MySQL in a shell script?! zaubara Programming 2 05-31-2004 05:27 PM
How get a mysql shell response in a script. philipina Programming 3 03-16-2004 11:51 AM


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