syntax issue with quotes in mysql command for a bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting syntax issue with quotes in mysql command for a bash script
# 1  
Old 04-21-2012
syntax issue with quotes in mysql command for a bash script

i'm trying to write a bash script that executes a mysql statement

mysql -sN -e INSERT INTO "$database"."$tableprefix"users (var1, var2,var3) VALUES (123, '1','')


i don't know where to put the quotes
it doesnt work with this one: `

it seems i can only put double quotes around the variables like $prefix

but if i put a single or double quote, or parrenthesis around the insert statement, it doesnt work..


how do i run this insert statement from a bash script?

thanks!

---------- Post updated at 03:32 AM ---------- Previous update was at 03:03 AM ----------

i figured it out
i put the query in between
EOF
and it worked

thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with quotes when running SQL command from within su -c

RHEL 6.2/Bash shell root user will be executing the below script. It switches to oracle user logs in using sqlplus and tries to run the below UPDATE statement. All the commands after su -c are enclosed in a single quote delimited by semicolon. The execution has failed because the quotes... (3 Replies)
Discussion started by: omega3
3 Replies

2. Web Development

Bash Script, ec2addtag syntax?

ec2addtag --region us-west-1 vol1234 --tag Name=$nameinst; It should execute ec2addtag --region us-west-1 vol1234 --tag Name=webserver; Instead it thinks that Name is equal to that variable. Please help. Thanks! Please use code tags! (0 Replies)
Discussion started by: svalenciatech
0 Replies

3. Shell Programming and Scripting

Issue with Single Quotes and Double Quotes for prompt PS1

Hi, Trying to change the prompt. I have the following code. export PS1=' <${USER}@`hostname -s`>$ ' The hostname is not displayed <abc@`hostname -s`>$ uname -a AIX xyz 1 6 00F736154C00 <adcwl4h@`hostname -s`>$ If I use double quotes, then the hostname is printed properly but... (3 Replies)
Discussion started by: bobbygsk
3 Replies

4. Shell Programming and Scripting

Nested double quotes won't work in my bash script?

In a bash script I have: LSCMD="find /project/media/ -mindepth 2 -maxdepth 2 -name \"files*pkg\"" ALL_PACKAGES=$( $LSCMD | sort 2>/dev/null) But I get nothing returned. It's just all blank. If I run the find command in a terminal, I get dozens of hits. I figure it's the way how I'm... (3 Replies)
Discussion started by: superbbrr
3 Replies

5. Shell Programming and Scripting

syntax issue mysql in bash script

I'm running mysql in a bash script mysql <<EOF query EOF one query is like this: UPDATE $dbname.$prefix"config" SET value = $var WHERE "$prefix"config.name = 'table colname'; with variable but it's giving an error i'm not sure what to put for "$prefix"config.name the table... (3 Replies)
Discussion started by: vanessafan99
3 Replies

6. Shell Programming and Scripting

How to run bash script from within MySQL

Can someone tell me the syntax to run a shell script from within MySQL? I know there is a way to do it, but I can't remember the syntax. I thought it was something like: mysql> \. /user/myscript; but I get this error: Failed to open file '/user/myscript;', error: 2 Please help!... (4 Replies)
Discussion started by: peterv6
4 Replies

7. Shell Programming and Scripting

bash syntax error: command not found

I am trying to create a shell that asks the user to enter their name, and compare it to my own by saying we have the same name or saying my name and that they have a nice name too. Here is my script... #!/bin/bash-x echo "Enter your name". read name if then echo "My name is Adam too"... (1 Reply)
Discussion started by: amaxey45
1 Replies

8. Shell Programming and Scripting

Help with a possiable syntax issue in my script

Hello I have tried to my best ability to work around this script tht will reference my m-names.txt which contains the format of: 168.16.0.0/16 169.56.0.0/16 132.2.0.0/16 122.5.0.0/16 Then I call a cli named getzoneprof that will set the $subnet from each of the lines in the... (6 Replies)
Discussion started by: richsark
6 Replies

9. Shell Programming and Scripting

BASH Script syntax error

I'm trying to write a simple script that takes all the .tar.gz files in a directory and verifies them by using the gzip -tv command: for zip in *.tar.gz do gzip -tv $zip if ; then #Check return code from tar echo "File ${zip} verified OK." exit... (4 Replies)
Discussion started by: kelldan
4 Replies

10. Shell Programming and Scripting

Retain quotes from bash script arguments

Hi there, I've been scouring these forums and have found similar threads, but none apparently helped me solved my problem :rolleyes: I'd like to run a command within a bash script, but that command is provided by the user to the script and may contain quotes, which is where the problem lies.... (9 Replies)
Discussion started by: cypression
9 Replies
Login or Register to Ask a Question
MYSQLDIFF(1p)						User Contributed Perl Documentation					     MYSQLDIFF(1p)

NAME
mysql-schema-diff - compare MySQL database schemas SYNOPSIS
mysql-schema-diff [B<options>] B<database1> B<database2> mysql-schema-diff --help DESCRIPTION
mysql-schema-diff is a Perl script front-end to the CPAN <http://www.perl.com/CPAN> module MySQL::Diff <http://search.cpan.org/search?module=MySQL::Diff> which compares the data structures (i.e. schema / table definitions) of two MySQL <http://www.mysql.com/> databases, and returns the differences as a sequence of MySQL commands suitable for piping into mysql which will transform the structure of the first database to be identical to that of the second (c.f. diff and patch). Database structures can be compared whether they are files containing table definitions or existing databases, local or remote. N.B. The program makes no attempt to compare any of the data which may be stored in the databases. It is purely for comparing the table definitions. I have no plans to implement data comparison; it is a complex problem and I have no need of such functionality anyway. However there is another program coldiff <http://rossbeyer.net/software/mysql_coldiff/> which does this, and is based on an older program called datadiff which seems to have vanished off the 'net. For PostgreSQL there are similar tools such as pgdiff <http://pgdiff.sourceforge.net/> and apgdiff <http://apgdiff.startnet.biz/>. EXAMPLES
# compare table definitions in two files mysql-schema-diff db1.mysql db2.mysql # compare table definitions in a file 'db1.mysql' with a database 'db2' mysql-schema-diff db1.mysql db2 # interactively upgrade schema of database 'db1' to be like the # schema described in the file 'db2.mysql' mysql-schema-diff -A db1 db2.mysql # compare table definitions in two databases on a remote machine mysql-schema-diff --host=remote.host.com --user=myaccount db1 db2 # compare table definitions in a local database 'foo' with a # database 'bar' on a remote machine, when a file foo already # exists in the current directory mysql-schema-diff --host2=remote.host.com --password=secret db:foo bar OPTIONS
More details to come; for now run "mysql-schema-diff --help". INTERNALS
For both of the database structures being compared, the following happens: o If the argument is a valid filename, the file is used to create a temporary database which "mysqldump -d" is run on to obtain the table definitions in canonicalised form. The temporary database is then dropped. (The temporary database is named "test_mysqldiff_temp_something" because default MySQL permissions allow anyone to create databases beginning with the prefix "test_".) o If the argument is a database, "mysqldump -d" is run directly on it. o Where authentication is required, the hostname, username, and password given by the corresponding options are used (type "mysql-schema-diff --help" for more information). o Each set of table definitions is now parsed into tables, and fields and index keys within those tables; these are compared, and the differences outputted in the form of MySQL statements. BUGS, DEVELOPMENT, CONTRIBUTING See <http://software.adamspiers.org/wiki/mysqldiff>. COPYRIGHT AND LICENSE
Copyright (c) 2000-2011 Adam Spiers. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
MySQL::Diff, MySQL::Diff::Database, MySQL::Diff::Table, MySQL::Diff::Utils, mysql, mysqldump, mysqlshow AUTHOR
Adam Spiers <mysqldiff@adamspiers.org> perl v5.14.2 2012-04-06 MYSQLDIFF(1p)