1

I'm trying to run an update query on a db server via bash command. I have to update an IP field (which is sorted as a string) but i'm getting a syntax error...

ssh [email protected] "/usr/local/mysql/bin/mysql -D SMARTPARK -u parkuser -ppass -e 'update client SET online=0 where client_ip='192.168.42.11''"

I'm getting as error

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.42.11' at line 1

which is the error?

2
  • 2
    There is a difference between quote and double-quote. Use "update client SET online=0 where client_ip='192.168.42.11'" Commented Apr 18, 2016 at 16:11
  • Actually you need to alternate between " and ' to make sure you don't escape from your script Commented Apr 18, 2016 at 16:14

1 Answer 1

1

Try to escape " character with \" to make sure you don't escape from the string you're sending to your DB.

In other words, try to put the following in the bash file you're executing:

ssh [email protected] "/usr/local/mysql/bin/mysql -D SMARTPARK -u parkuser -ppass -e \"update client SET online=0 where client_ip='192.168.42.11'\""
Sign up to request clarification or add additional context in comments.

4 Comments

ok, I have no more the error, but the command looks like I ran the -h command because I see all the help prompt and the query is not made...
@besmart Could you try again with my last edit's suggestion?
changing to your last edit gives me back syntax error
@besmart I tried with a script of my own with escaped ", i.e. \", it worked just fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.