LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices

Reply
 
Search this Thread
Old 08-18-2004, 07:39 AM   #1
acrors
Member
 
Registered: Aug 2004
Posts: 72

Rep: Reputation: 15
Mysql in bash script


I would like to run some commands of mysql automaticly in rh9, but i don't know how to create mysql script file in bash script.
Pls show me ...
I know how to script but i don't know how to script with mysql ....
Give me a simple and runable example ...

Thank you
 
Old 08-18-2004, 07:59 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
You could use a 'here document'.

From man bash:

This type of redirection instructs the shell to read input from the current source until a line containing only word (with no trailing blanks) is seen. All of the lines read up to that point are then used as the standard input for a command.

#!/bin/bash
<some other code>

mysql <<EOF
command 1
command 2
command 3
EOF

From within the script mysql is started and everything between the first and the last EOF is given to mysql and executed by mysql.

Example (sqlplus, but principle is the same):
sqlplus -silent <<SQLscript
user/passwd
set linesize 122
set pagesize 0
set heading off

spool $result
select substr(u.user_name,1,10),';',
substr(u.full_name,1,20),';',
substr(u.description,1,40),';',
substr(t.template,1,20)
from smf_user u, smf_user_access a, smf_template t
where u.user_name=a.user_name
and a.template_id=t.template_id
order by t.template , u.description
;
spool off
exit 0
SQLscript


Hope this gets you going again.
 
Old 08-18-2004, 09:11 PM   #3
acrors
Member
 
Registered: Aug 2004
Posts: 72

Original Poster
Rep: Reputation: 15
thank you for your help ...
i'm clear now ...
 
  


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
Bash + Mysql Help xianzai Programming 4 10-28-2004 08:15 AM
Bash script and mysql flashingcurser Programming 1 07-19-2004 03:35 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM


All times are GMT -5. The time now is 05:44 PM.

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