Link to home
Start Free TrialLog in
Avatar of wesly_chen
wesly_chenFlag for United States of America

asked on

How to pass shell variable into "mysql -e" querry

Hi,

I need to pass the shell variable into mysql -e query in bash shell command line

$ export ID=0
$ mysql -e 'select * from user where id=$ID'
ERROR 1054 (42S22) at line 1: Unknown column '$ID' in 'where clause'
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

this is, AFAIK, not possible.
you will have to build a text file with the query, and use that file as input for running the query.
Avatar of wesly_chen

ASKER

> build a text file with the query, and use that file as input for running the query.
How?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> echo "exit;" >> file.sql
it complains about syntax error. I take out ";" and everything is ok now.

Thanks a lot.