Unexpected EOF in mysql shell script

2019-08-29 23:55发布

问题:

I'm getting some mysql info from shell like this:

#!/bin/bash
keyOrPass=$1
intercom=$2
flat=$3
number=$4
mysql -ulogin -ppassword db_name << EOF
select codeGuestEmail, codePrivateEmail from mbus_clients WHERE flat=$flat and domophone=$intercom;
EOF

I found this solution in some tutorial, but it says: check the manual that corresponds to your MySQL server version for the right syntax to use near 'EOF' What's wrong? How can I finish mysql session? http://www.cyberciti.biz/faq/using-mysql-in-shell-scripts/ here is example of tutorial where I found solution.
UPDATE added different quotes to EOF doesn't work too.

回答1:

in your query pass the dynamic variable with quotes ..

select codeGuestEmail, codePrivateEmail from mbus_clients WHERE flat='$flat' and domophone='$intercom';

or try with this

select codeGuestEmail, codePrivateEmail from mbus_clients WHERE flat=${flat} and domophone=${intercom};


标签: mysql shell