Unexpected EOF in mysql shell script

2019-08-29 23:37发布

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.

标签: mysql shell
1条回答
劫难
2楼-- · 2019-08-30 00:24

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};
查看更多
登录 后发表回答