Mysql Script File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mysql Script File
# 1  
Old 12-06-2007
Mysql Script File

Hi,

I'm trying to develop a script file that can manipulate a mysql database. I can query the db no problem... That is until I try to create a function that will do the work for me. I've tested several scenarios to try to get around it. But I can't seem to find anything that will work when passing queries via a function. The basic code included below has testing provisions that can be uncommented.

Also, when running this with ksh -x. The input to mysql is identical whether or not the function is being used. The read statement fails when run withing a function.

Any Ideas???

Thanks

Code:
#! /bin/ksh
# 
mysql -u root  -D ftp_files -ss -n -q |&
################################################################################
# Fucntions
################################################################################
# Query db: Perform a database query.
################################################################################
query_db(){
  print -p -- "$query"
  read -p "$get_row_count1"
}
################################################################################
# End Fucntions
################################################################################
################################################################################
# Testing w/wo variable and no function. WORKS
################################################################################
# Use these two...
################################################################################
#query="$2"
#print -p -- "$query"
################################################################################
# or this one with the read and echo below.
################################################################################
#print -p -- "select * from usr where id='1';"
################################################################################
#echo "Testing w/wo variable and no function."
#read -p get_row_count1
#echo $get_row_count1
#exit
################################################################################
# Main DOESN'T WORK
################################################################################
if [ ! "$#" -eq "2" ]
then
  echo "Usage: $0 \"query string\""
  exit
fi

query="$2"

$1 "$query"

echo "$get_row_count1"
exit
################################################################################
# END
################################################################################

# 2  
Old 12-06-2007
Never mind, I'm an id10t. There was a $ on the read statement in the function.

I'd rather have a bottle in front of me, than a frontal lobotomy!
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using bash script : How to Import data from a dsv file into multiple tables in mysql

HI I have a dsv file that looks like: <<BOF>> record_number|id_number|first name|last name|msisdn|network|points|card number|gender 312|9101011234011|Test Junior|Smith|071 123 4321|MTN|73|1241551413214444|M 313|9012023213011|Bob|Smith|27743334321|Vodacom|3|1231233232323244|M... (4 Replies)
Discussion started by: tera
4 Replies

2. UNIX and Linux Applications

MySQL Daemon failed to start - no mysql.sock file

After doing a yum install mysql mysql-server on Fedora 14 I wasn't able to fully install the packages correctly. It installed MySQL 5.1. I was getting the following error when running the: mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)... (3 Replies)
Discussion started by: jastanle84
3 Replies

3. Shell Programming and Scripting

Help with Script - mysql

Hello. First of all thanks for everybody helping on this forum. It's my first post on here but this forum helped me a lot many times. I'm making a small script, that creates folders that you type, and copy wordpress on it. Far that it works, problem is when I want to create databases with... (10 Replies)
Discussion started by: PoloBGS
10 Replies

4. Shell Programming and Scripting

Writing file name and date from LS command into a file to be imported into mysql

I am looking to do a ls on a folder and have the output of the ls be structured so that is is modificaiton date, file name with the date in a format that is compatible with mysql. I am trying to build a table that stores the last modification date of certain files so I can display it on some web... (4 Replies)
Discussion started by: personalt
4 Replies

5. Shell Programming and Scripting

Can't add variable to file name in mySQL dump script

I have a script (below) which works ok, but I have tried to modify it as I want to keep the older files for a restore if needed. I have tried adding a date suffix to the newly created files (second lump of code), but it doesn't seem to work. I get the error: $SOURCEDIR/p1db_$DATEVAR.sql:... (3 Replies)
Discussion started by: ojobson
3 Replies

6. Shell Programming and Scripting

Exporting .csv file into mysql server 2005 using script.

Hi, I have a .csv file created by a script with data in a tabular format. I need to insert all the value into mysql database which is running in a different machine. what is the command to export the .csv file into database using shell script. Thanks in advance. (3 Replies)
Discussion started by: ahamed
3 Replies
Login or Register to Ask a Question