Reputation: 49
Trying to write an table update statement in my bash script but gives me a syntax error mysql Ver 15.1 Distrib 5.5.68-MariaDB, for Linux (x86_64) using readline 5.1
mysql -u UserName --password=MyPassword -D MyDatabase -e 'UPDATE MyTable SET name = SomeName WHERE number = someNumber ;'
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SomeName WHERE number = someNumber' at line 1
Upvotes: 1
Views: 1556
Reputation: 49
So the answer is: you must escape "" like so \" one liner to update mysql db from shell:
mysql -u userName --password=yourPassword -D databaseName -e "UPDATE tableName SET columnName = \"${variable}\" WHERE numberColumn = \"${numberVariable}\""
Upvotes: 1