Ramratan Gupta Ramratan Gupta - 4 months ago 11
SQL Question

Error while passing argument as SQL to MYSQL via -e with like where condition

Hi I am trying to do below on Ubuntu terminal

mysql -u root -proot -e "SELECT * FROM knexus.redis_cache WHERE `key` LIKE '%hub.local%'"


I am getting below error


The program 'key' is currently not installed. You can install it by typing:

sudo apt-get install donkey

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 'LIKE '%hub.local%'' at line 1


However SQL run properly on MYSQL terminal.

I guess this might be issue character escaping issue, as I see
sudo apt-get install donkey
.

Answer

The ticks framing key cause the bash to treat key as a command and replace it by its output in the command. You could either try without them or put the whole command in single quotes and the %hub.local% in double quotes.