wesly_chen
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'
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'
ASKER
> build a text file with the query, and use that file as input for running the query.
How?
How?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
> echo "exit;" >> file.sql
it complains about syntax error. I take out ";" and everything is ok now.
Thanks a lot.
it complains about syntax error. I take out ";" and everything is ok now.
Thanks a lot.
you will have to build a text file with the query, and use that file as input for running the query.